Skip to content

Commit

Permalink
FINERACT-2097: Support for string type primary keys - part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Marta Jankovics committed Jul 5, 2024
1 parent 0358921 commit f1ae0c6
Show file tree
Hide file tree
Showing 135 changed files with 1,465 additions and 1,384 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ buildscript {

dependencies {
classpath 'com.bmuschko:gradle-cargo-plugin:2.9.0'
classpath 'org.eclipse.persistence:eclipselink:4.0.0'
classpath 'org.eclipse.persistence:eclipselink:4.0.2'
classpath 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0'
classpath 'com.google.cloud.tools:jib-layer-filter-extension-gradle:0.3.0'
classpath 'org.apache.commons:commons-lang3:3.14.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencyManagement {
dependency 'org.codehaus.janino:janino:3.1.11'


dependency 'org.eclipse.persistence:org.eclipse.persistence.jpa:4.0.0'
dependency 'org.eclipse.persistence:org.eclipse.persistence.jpa:4.0.2'
dependency 'com.google.guava:guava:32.0.0-jre'
dependency 'com.google.code.gson:gson:2.10.1'
dependency 'com.google.truth:truth:1.4.0'
Expand Down Expand Up @@ -239,5 +239,7 @@ dependencyManagement {
dependency 'org.apache.commons:commons-math3:3.6.1'

dependency 'org.mockito:mockito-inline:5.2.0'

dependency 'com.aventrix.jnanoid:jnanoid:2.0.0'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/
package com.acme.fineract.portfolio.note.service;

import java.util.Collection;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.portfolio.note.data.NoteData;
import org.apache.fineract.portfolio.note.domain.NoteType;
import org.apache.fineract.portfolio.note.service.NoteReadPlatformService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -37,12 +38,12 @@ public void afterPropertiesSet() throws Exception {
}

@Override
public NoteData retrieveNote(Long noteId, Long resourceId, Integer noteTypeId) {
public NoteData retrieveNote(Long noteId, String resourceId, NoteType noteType) {
return null;
}

@Override
public Collection<NoteData> retrieveNotesByResource(Long resourceId, Integer noteTypeId) {
public List<NoteData> retrieveNotesByResource(String resourceId, NoteType noteType) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
*/
package com.acme.fineract.portfolio.note.service;

import java.io.Serializable;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.client.domain.Client;
import org.apache.fineract.portfolio.note.domain.NoteType;
import org.apache.fineract.portfolio.note.service.NoteWritePlatformService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -53,7 +54,7 @@ public CommandProcessingResult deleteNote(JsonCommand command) {
}

@Override
public void createAndPersistClientNote(Client client, JsonCommand command) {

public Long createEntityNote(NoteType type, Serializable resourceId, JsonCommand command) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ Page<JournalEntryData> retrieveAll(SearchParameters searchParameters, Long glAcc
JournalEntryAssociationParametersData associationParametersData);

OfficeOpeningBalancesData retrieveOfficeOpeningBalances(Long officeId, String currencyCode);

Page<JournalEntryData> retrieveJournalEntriesByEntityId(String transactionId, Long entityId, Integer entityType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class ProductToGLAccountMapping extends AbstractPersistableCustom<Long> {
@Column(name = "product_id", nullable = true)
private Long productId;

@Column(name = "product_identifier", nullable = true)
private String productIdentifier;

@ManyToOne
@JoinColumn(name = "payment_type", nullable = true)
private PaymentType paymentType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,20 @@ List<ProductToGLAccountMapping> findAllPenaltyToIncomeAccountMappings(@Param("pr
@Param("productType") int productType);

List<ProductToGLAccountMapping> findByProductIdAndProductType(Long productId, int productType);

List<ProductToGLAccountMapping> findByProductIdentifierAndProductType(String productIdentifier, int productType);

@Query("select mapping from ProductToGLAccountMapping mapping where mapping.productIdentifier =:productIdentifier and mapping.productType =:productType and mapping.financialAccountType=:financialAccountType and mapping.paymentType is NULL and mapping.charge is NULL")
ProductToGLAccountMapping findCoreProductToFinAccountMapping(@Param("productIdentifier") String productIdentifier,
@Param("productType") int productType, @Param("financialAccountType") int financialAccountType);

/***
* The financial Account Type for a fund source will always be an asset (1)
***/
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.productIdentifier =:productIdentifier and mapping.productType =:productType and mapping.financialAccountType=1 and mapping.paymentType is not NULL")
List<ProductToGLAccountMapping> findAllPaymentTypeToFundSourceMappings(@Param("productIdentifier") String productIdentifier,
@Param("productType") int productType);

ProductToGLAccountMapping findByProductIdentifierAndProductTypeAndFinancialAccountTypeAndPaymentTypeId(String productIdentifier,
int productType, int financialAccountType, Long paymentType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public ProductToGLAccountMappingNotFoundException(final PortfolioProductType typ
super("error.msg.productToAccountMapping.not.found", "Mapping for product of type " + type.toString() + " with Id " + productId
+ " does not exist for an account of type " + accountType, type.toString(), productId, accountType);
}

public ProductToGLAccountMappingNotFoundException(final PortfolioProductType type, final String productId, final String accountType) {
super("error.msg.productToAccountMapping.not.found", "Mapping for product of type " + type + " with Identifier " + productId
+ " does not exist for an account of type " + accountType, type, productId, accountType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.fineract.accounting.common.AccountingConstants.CashAccountsForLoan;
import org.apache.fineract.accounting.common.AccountingConstants.LoanProductAccountingParams;
import org.apache.fineract.accounting.glaccount.domain.GLAccount;
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper;
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMapping;
Expand All @@ -52,13 +51,10 @@
@RequiredArgsConstructor
public class ProductToGLAccountMappingHelper {

protected static final List<GLAccountType> ASSET_LIABILITY_TYPES = List.of(GLAccountType.ASSET, GLAccountType.LIABILITY);

protected final GLAccountRepository accountRepository;
protected final ProductToGLAccountMappingRepository accountMappingRepository;
protected final FromJsonHelper fromApiJsonHelper;
private final ProductToGLAccountMappingRepository accountMappingRepository;
private final FromJsonHelper fromApiJsonHelper;
private final ChargeRepositoryWrapper chargeRepositoryWrapper;
protected final GLAccountRepositoryWrapper accountRepositoryWrapper;
private final GLAccountRepositoryWrapper accountRepositoryWrapper;
private final PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper;

public void saveProductToAccountMapping(final JsonElement element, final String paramName, final Long productId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,51 @@
import com.google.gson.JsonElement;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.accounting.common.AccountingConstants;
import org.apache.fineract.accounting.common.AccountingConstants.AccrualAccountsForSavings;
import org.apache.fineract.accounting.common.AccountingConstants.CashAccountsForSavings;
import org.apache.fineract.accounting.common.AccountingConstants.SavingProductAccountingParams;
import org.apache.fineract.accounting.common.AccountingRuleType;
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepositoryWrapper;
import org.apache.fineract.accounting.glaccount.domain.GLAccountType;
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMappingRepository;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
import org.apache.fineract.portfolio.PortfolioProductType;
import org.apache.fineract.portfolio.charge.domain.ChargeRepositoryWrapper;
import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper;
import org.springframework.stereotype.Component;

@Component
public class SavingsProductToGLAccountMappingHelper extends ProductToGLAccountMappingHelper {

public SavingsProductToGLAccountMappingHelper(final GLAccountRepository glAccountRepository,
final ProductToGLAccountMappingRepository glAccountMappingRepository, final FromJsonHelper fromApiJsonHelper,
final ChargeRepositoryWrapper chargeRepositoryWrapper, final GLAccountRepositoryWrapper accountRepositoryWrapper,
final PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper) {
super(glAccountRepository, glAccountMappingRepository, fromApiJsonHelper, chargeRepositoryWrapper, accountRepositoryWrapper,
paymentTypeRepositoryWrapper);
}
@RequiredArgsConstructor
public class SavingsProductToGLAccountMappingHelper {

private final FromJsonHelper fromApiJsonHelper;
private final ProductToGLAccountMappingHelper productToGLAccountMappingHelper;

/***
* Set of abstractions for saving Saving Products to GL Account Mappings
***/

public void saveSavingsToAssetAccountMapping(final JsonElement element, final String paramName, final Long productId,
final int placeHolderTypeId) {
saveProductToAccountMapping(element, paramName, productId, placeHolderTypeId, GLAccountType.ASSET, PortfolioProductType.SAVING);
productToGLAccountMappingHelper.saveProductToAccountMapping(element, paramName, productId, placeHolderTypeId, GLAccountType.ASSET,
PortfolioProductType.SAVING);
}

public void saveSavingsToIncomeAccountMapping(final JsonElement element, final String paramName, final Long productId,
final int placeHolderTypeId) {
saveProductToAccountMapping(element, paramName, productId, placeHolderTypeId, GLAccountType.INCOME, PortfolioProductType.SAVING);
productToGLAccountMappingHelper.saveProductToAccountMapping(element, paramName, productId, placeHolderTypeId, GLAccountType.INCOME,
PortfolioProductType.SAVING);
}

public void saveSavingsToExpenseAccountMapping(final JsonElement element, final String paramName, final Long productId,
final int placeHolderTypeId) {
saveProductToAccountMapping(element, paramName, productId, placeHolderTypeId, GLAccountType.EXPENSE, PortfolioProductType.SAVING);
productToGLAccountMappingHelper.saveProductToAccountMapping(element, paramName, productId, placeHolderTypeId, GLAccountType.EXPENSE,
PortfolioProductType.SAVING);
}

public void saveSavingsToLiabilityAccountMapping(final JsonElement element, final String paramName, final Long productId,
final int placeHolderTypeId) {
saveProductToAccountMapping(element, paramName, productId, placeHolderTypeId, GLAccountType.LIABILITY, PortfolioProductType.SAVING);
productToGLAccountMappingHelper.saveProductToAccountMapping(element, paramName, productId, placeHolderTypeId,
GLAccountType.LIABILITY, PortfolioProductType.SAVING);
}

/***
Expand All @@ -77,58 +74,64 @@ public void saveSavingsToLiabilityAccountMapping(final JsonElement element, fina

public void mergeSavingsToAssetAccountMappingChanges(final JsonElement element, final String paramName, final Long productId,
final int accountTypeId, final String accountTypeName, final Map<String, Object> changes) {
mergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, accountTypeName, changes, GLAccountType.ASSET,
PortfolioProductType.SAVING);
productToGLAccountMappingHelper.mergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, accountTypeName,
changes, GLAccountType.ASSET, PortfolioProductType.SAVING);
}

public void mergeSavingsToIncomeAccountMappingChanges(final JsonElement element, final String paramName, final Long productId,
final int accountTypeId, final String accountTypeName, final Map<String, Object> changes) {
mergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, accountTypeName, changes, GLAccountType.INCOME,
PortfolioProductType.SAVING);
productToGLAccountMappingHelper.mergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, accountTypeName,
changes, GLAccountType.INCOME, PortfolioProductType.SAVING);
}

public void mergeSavingsToExpenseAccountMappingChanges(final JsonElement element, final String paramName, final Long productId,
final int accountTypeId, final String accountTypeName, final Map<String, Object> changes) {
mergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, accountTypeName, changes, GLAccountType.EXPENSE,
PortfolioProductType.SAVING);
productToGLAccountMappingHelper.mergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, accountTypeName,
changes, GLAccountType.EXPENSE, PortfolioProductType.SAVING);
}

public void mergeSavingsToLiabilityAccountMappingChanges(final JsonElement element, final String paramName, final Long productId,
final int accountTypeId, final String accountTypeName, final Map<String, Object> changes) {
mergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, accountTypeName, changes, GLAccountType.LIABILITY,
PortfolioProductType.SAVING);
productToGLAccountMappingHelper.mergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, accountTypeName,
changes, GLAccountType.LIABILITY, PortfolioProductType.SAVING);
}

public void createOrmergeSavingsToLiabilityAccountMappingChanges(final JsonElement element, final String paramName,
final Long productId, final int accountTypeId, final Map<String, Object> changes) {
createOrmergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, changes, GLAccountType.LIABILITY,
PortfolioProductType.SAVING);
productToGLAccountMappingHelper.createOrmergeProductToAccountMappingChanges(element, paramName, productId, accountTypeId, changes,
GLAccountType.LIABILITY, PortfolioProductType.SAVING);
}

/*** Abstractions for payments channel related to savings products ***/

public void savePaymentChannelToFundSourceMappings(final JsonCommand command, final JsonElement element, final Long productId,
final Map<String, Object> changes) {
savePaymentChannelToFundSourceMappings(command, element, productId, changes, PortfolioProductType.SAVING);
productToGLAccountMappingHelper.savePaymentChannelToFundSourceMappings(command, element, productId, changes,
PortfolioProductType.SAVING);
}

public void updatePaymentChannelToFundSourceMappings(final JsonCommand command, final JsonElement element, final Long productId,
final Map<String, Object> changes) {
updatePaymentChannelToFundSourceMappings(command, element, productId, changes, PortfolioProductType.SAVING);
productToGLAccountMappingHelper.updatePaymentChannelToFundSourceMappings(command, element, productId, changes,
PortfolioProductType.SAVING);
}

public void saveChargesToIncomeAccountMappings(final JsonCommand command, final JsonElement element, final Long productId,
final Map<String, Object> changes) {
// save both fee and penalty charges
saveChargesToGLAccountMappings(command, element, productId, changes, PortfolioProductType.SAVING, true);
saveChargesToGLAccountMappings(command, element, productId, changes, PortfolioProductType.SAVING, false);
productToGLAccountMappingHelper.saveChargesToGLAccountMappings(command, element, productId, changes, PortfolioProductType.SAVING,
true);
productToGLAccountMappingHelper.saveChargesToGLAccountMappings(command, element, productId, changes, PortfolioProductType.SAVING,
false);
}

public void updateChargesToIncomeAccountMappings(final JsonCommand command, final JsonElement element, final Long productId,
final Map<String, Object> changes) {
// update both fee and penalty charges
updateChargeToIncomeAccountMappings(command, element, productId, changes, PortfolioProductType.SAVING, true);
updateChargeToIncomeAccountMappings(command, element, productId, changes, PortfolioProductType.SAVING, false);
productToGLAccountMappingHelper.updateChargeToIncomeAccountMappings(command, element, productId, changes,
PortfolioProductType.SAVING, true);
productToGLAccountMappingHelper.updateChargeToIncomeAccountMappings(command, element, productId, changes,
PortfolioProductType.SAVING, false);
}

public Map<String, Object> populateChangesForNewSavingsProductToGLAccountMappingCreation(final JsonElement element,
Expand All @@ -143,8 +146,8 @@ public Map<String, Object> populateChangesForNewSavingsProductToGLAccountMapping
.extractLongNamed(SavingProductAccountingParams.INCOME_FROM_PENALTIES.getValue(), element);
final Long interestOnSavingsId = this.fromApiJsonHelper
.extractLongNamed(SavingProductAccountingParams.INTEREST_ON_SAVINGS.getValue(), element);
final Long savingsControlId = this.fromApiJsonHelper.extractLongNamed(SavingProductAccountingParams.SAVINGS_CONTROL.getValue(),
element);
final Long savingsControlId = this.fromApiJsonHelper
.extractLongNamed(AccountingConstants.SavingProductAccountingParams.SAVINGS_CONTROL.getValue(), element);
final Long transfersInSuspenseAccountId = this.fromApiJsonHelper
.extractLongNamed(SavingProductAccountingParams.TRANSFERS_SUSPENSE.getValue(), element);
final Long overdraftControlId = this.fromApiJsonHelper
Expand Down Expand Up @@ -311,6 +314,6 @@ public void handleChangesToSavingsProductToGLAccountMappings(final Long savingsP
}

public void deleteSavingsProductToGLAccountMapping(final Long savingsProductId) {
deleteProductToGLAccountMapping(savingsProductId, PortfolioProductType.SAVING);
productToGLAccountMappingHelper.deleteProductToGLAccountMapping(savingsProductId, PortfolioProductType.SAVING);
}
}
Loading

0 comments on commit f1ae0c6

Please sign in to comment.