Shares Integration Tests and Fixes
This commit is contained in:
+33
-23
@@ -18,8 +18,6 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.accounts.api;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
@@ -39,10 +37,13 @@ import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.apache.fineract.infrastructure.core.service.Page;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.portfolio.accounts.constants.AccountsApiConstants;
|
||||
import org.apache.fineract.portfolio.accounts.data.AccountData;
|
||||
import org.apache.fineract.portfolio.accounts.service.AccountReadPlatformService;
|
||||
import org.apache.fineract.portfolio.products.exception.ResourceNotFoundException;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -59,21 +60,18 @@ public class AccountsApiResource {
|
||||
private final DefaultToApiJsonSerializer<AccountData> toApiJsonSerializer;
|
||||
private final PlatformSecurityContext platformSecurityContext;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
private final DefaultToApiJsonSerializer<Object> toApiObjectJsonSerializer ;
|
||||
|
||||
@Autowired
|
||||
public AccountsApiResource(final ApplicationContext applicationContext,
|
||||
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final DefaultToApiJsonSerializer<AccountData> toApiJsonSerializer,
|
||||
final PlatformSecurityContext platformSecurityContext,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||
final DefaultToApiJsonSerializer<Object> toApiObjectJsonSerializer) {
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.applicationContext = applicationContext ;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper ;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer ;
|
||||
this.platformSecurityContext = platformSecurityContext ;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService ;
|
||||
this.toApiObjectJsonSerializer = toApiObjectJsonSerializer ;
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -83,12 +81,16 @@ public class AccountsApiResource {
|
||||
public String template(@PathParam("type") final String accountType, @QueryParam("clientId") final Long clientId,
|
||||
@QueryParam("productId") final Long productId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
this.platformSecurityContext.authenticatedUser() ;
|
||||
String serviceName = accountType+AccountsApiConstants.READPLATFORM_NAME ;
|
||||
AccountReadPlatformService service = (AccountReadPlatformService) this.applicationContext.getBean(serviceName) ;
|
||||
final AccountData accountData = service.retrieveTemplate(clientId, productId);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, accountData, service.getResponseDataParams());
|
||||
try {
|
||||
this.platformSecurityContext.authenticatedUser() ;
|
||||
String serviceName = accountType+AccountsApiConstants.READPLATFORM_NAME ;
|
||||
AccountReadPlatformService service = (AccountReadPlatformService) this.applicationContext.getBean(serviceName) ;
|
||||
final AccountData accountData = service.retrieveTemplate(clientId, productId);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, accountData, service.getResponseDataParams());
|
||||
}catch(BeansException e) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -97,22 +99,30 @@ public class AccountsApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAccount(@PathParam("accountId") final Long accountId, @PathParam("type") final String accountType,
|
||||
@Context final UriInfo uriInfo) {
|
||||
String serviceName = accountType+AccountsApiConstants.READPLATFORM_NAME ;
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
AccountReadPlatformService service = (AccountReadPlatformService) this.applicationContext.getBean(serviceName) ;
|
||||
AccountData data = service.retrieveOne(accountId, settings.isTemplate()) ;
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
try {
|
||||
String serviceName = accountType+AccountsApiConstants.READPLATFORM_NAME ;
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
AccountReadPlatformService service = (AccountReadPlatformService) this.applicationContext.getBean(serviceName) ;
|
||||
AccountData data = service.retrieveOne(accountId, settings.isTemplate()) ;
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
}catch(BeansException e) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllAccounts(@PathParam("type") final String accountType, @Context final UriInfo uriInfo) {
|
||||
String serviceName = accountType+AccountsApiConstants.READPLATFORM_NAME ;
|
||||
AccountReadPlatformService service = (AccountReadPlatformService) this.applicationContext.getBean(serviceName) ;
|
||||
Collection<AccountData> data = service.retrieveAll() ;
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
public String retrieveAllAccounts(@PathParam("type") final String accountType, @QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit, @Context final UriInfo uriInfo) {
|
||||
try {
|
||||
String serviceName = accountType+AccountsApiConstants.READPLATFORM_NAME ;
|
||||
AccountReadPlatformService service = (AccountReadPlatformService) this.applicationContext.getBean(serviceName) ;
|
||||
Page<AccountData> data = service.retrieveAll(offset, limit) ;
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
}catch(BeansException e) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
|
||||
+2
-2
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.accounts.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.service.Page;
|
||||
import org.apache.fineract.portfolio.accounts.data.AccountData;
|
||||
|
||||
public interface AccountReadPlatformService {
|
||||
@@ -29,7 +29,7 @@ public interface AccountReadPlatformService {
|
||||
|
||||
public AccountData retrieveOne(Long id, boolean includeTemplate);
|
||||
|
||||
public Collection<AccountData> retrieveAll();
|
||||
public Page<AccountData> retrieveAll(final Integer offSet, final Integer limit);
|
||||
|
||||
public Set<String> getResponseDataParams();
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.apache.fineract.portfolio.group.domain.Group;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
|
||||
import org.apache.fineract.portfolio.savings.domain.SavingsAccount;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccount;
|
||||
import org.apache.fineract.useradministration.domain.AppUser;
|
||||
|
||||
@Entity
|
||||
@@ -67,6 +68,11 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
|
||||
@JoinColumn(name = "savings_account_id", nullable = true)
|
||||
private SavingsAccount savingsAccount;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "share_account_id", nullable = true)
|
||||
private ShareAccount shareAccount;
|
||||
|
||||
|
||||
public static Note clientNoteFromJson(final Client client, final JsonCommand command) {
|
||||
final String note = command.stringValueOfParameterNamed("note");
|
||||
return new Note(client, note);
|
||||
@@ -89,6 +95,10 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
|
||||
return new Note(account, note);
|
||||
}
|
||||
|
||||
public static Note shareNote(final ShareAccount account, final String note) {
|
||||
return new Note(account, note);
|
||||
}
|
||||
|
||||
public Note(final Client client, final String note) {
|
||||
this.client = client;
|
||||
this.note = note;
|
||||
@@ -133,6 +143,13 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
|
||||
this.noteTypeId = NoteType.SAVING_ACCOUNT.getValue();
|
||||
}
|
||||
|
||||
public Note(final ShareAccount account, final String note) {
|
||||
this.shareAccount = account;
|
||||
this.client = account.getClient();
|
||||
this.note = note;
|
||||
this.noteTypeId = NoteType.SHARE_ACCOUNT.getValue();
|
||||
}
|
||||
|
||||
public Map<String, Object> update(final JsonCommand command) {
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(7);
|
||||
|
||||
|
||||
+3
-2
@@ -27,8 +27,9 @@ public enum NoteType {
|
||||
LOAN(200, "noteType.loan", "loans"), //
|
||||
LOAN_TRANSACTION(300, "noteType.loan.transaction", "loanTransactions"), //
|
||||
SAVING_ACCOUNT(500, "noteType.saving", "savings"), //
|
||||
GROUP(600, "noteType.group", "groups");
|
||||
|
||||
GROUP(600, "noteType.group", "groups"),
|
||||
SHARE_ACCOUNT(700, "noteType.shares", "accounts/share");
|
||||
|
||||
private Integer value;
|
||||
private String code;
|
||||
private String apiUrl;
|
||||
|
||||
+30
-31
@@ -30,7 +30,6 @@ import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.fineract.commands.domain.CommandWrapper;
|
||||
import org.apache.fineract.commands.service.CommandWrapperBuilder;
|
||||
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
@@ -42,7 +41,9 @@ import org.apache.fineract.infrastructure.core.service.Page;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.portfolio.products.constants.ProductsApiConstants;
|
||||
import org.apache.fineract.portfolio.products.data.ProductData;
|
||||
import org.apache.fineract.portfolio.products.exception.ResourceNotFoundException;
|
||||
import org.apache.fineract.portfolio.products.service.ProductReadPlatformService;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -56,21 +57,18 @@ public class ProductsApiResource {
|
||||
private final ApplicationContext applicationContext;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final DefaultToApiJsonSerializer<ProductData> toApiJsonSerializer;
|
||||
private final DefaultToApiJsonSerializer<Object> toApiObjectJsonSerializer;
|
||||
private final PlatformSecurityContext platformSecurityContext;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public ProductsApiResource(final ApplicationContext applicationContext, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final DefaultToApiJsonSerializer<ProductData> toApiJsonSerializer, final PlatformSecurityContext platformSecurityContext,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||
final DefaultToApiJsonSerializer<Object> toApiDividendsJsonSerializer) {
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.applicationContext = applicationContext;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.platformSecurityContext = platformSecurityContext;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
this.toApiObjectJsonSerializer = toApiDividendsJsonSerializer;
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -79,10 +77,14 @@ public class ProductsApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveTemplate(@PathParam("type") final String productType, @Context final UriInfo uriInfo) {
|
||||
String serviceName = productType + ProductsApiConstants.READPLATFORM_NAME;
|
||||
ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName);
|
||||
ProductData data = service.retrieveTemplate();
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
try {
|
||||
ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName);
|
||||
ProductData data = service.retrieveTemplate();
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
}catch(BeansException e) {
|
||||
throw new ResourceNotFoundException() ;
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -91,30 +93,31 @@ public class ProductsApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveProduct(@PathParam("productId") final Long productId, @PathParam("type") final String productType,
|
||||
@Context final UriInfo uriInfo) {
|
||||
String serviceName = productType + ProductsApiConstants.READPLATFORM_NAME;
|
||||
ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
ProductData data = service.retrieveOne(productId, settings.isTemplate());
|
||||
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
try {
|
||||
String serviceName = productType + ProductsApiConstants.READPLATFORM_NAME;
|
||||
ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
ProductData data = service.retrieveOne(productId, settings.isTemplate());
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
} catch (BeansException e) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String retrieveAllProducts(/*
|
||||
* @PathParam("type") final String
|
||||
* productType, @Context final UriInfo
|
||||
* uriInfo
|
||||
*/
|
||||
@PathParam("type") final String productType, @QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
|
||||
public String retrieveAllProducts(@PathParam("type") final String productType, @QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
|
||||
@Context final UriInfo uriInfo) {
|
||||
String serviceName = productType + ProductsApiConstants.READPLATFORM_NAME;
|
||||
ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName);
|
||||
Page<ProductData> data = service.retrieveAllProducts(offset, limit);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
try {
|
||||
String serviceName = productType + ProductsApiConstants.READPLATFORM_NAME;
|
||||
ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName);
|
||||
Page<ProductData> data = service.retrieveAllProducts(offset, limit);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, data, service.getResponseDataParams());
|
||||
}catch(BeansException e) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -152,8 +155,4 @@ public class ProductsApiResource {
|
||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
private boolean is(final String commandParam, final String commandValue) {
|
||||
return StringUtils.isNotBlank(commandParam) && commandParam.trim().equalsIgnoreCase(commandValue);
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.portfolio.products.exception;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
|
||||
public class ResourceNotFoundException extends AbstractPlatformResourceNotFoundException{
|
||||
|
||||
public ResourceNotFoundException(String globalisationMessageCode, String defaultUserMessage, Object[] defaultUserMessageArgs) {
|
||||
super(globalisationMessageCode, defaultUserMessage, defaultUserMessageArgs);
|
||||
}
|
||||
|
||||
public ResourceNotFoundException() {
|
||||
super("","","") ;
|
||||
}
|
||||
}
|
||||
+27
-2
@@ -262,9 +262,18 @@ public class ShareAccount extends AbstractPersistable<Long> {
|
||||
public void addTransaction(final ShareAccountTransaction transaction) {
|
||||
transaction.setShareAccount(this);
|
||||
if(transaction.isPendingForApprovalTransaction()) {
|
||||
this.totalSharesPending += transaction.getTotalShares() ;
|
||||
if(this.totalSharesPending == null) {
|
||||
this.totalSharesPending = transaction.getTotalShares() ;
|
||||
}else {
|
||||
this.totalSharesPending += transaction.getTotalShares() ;
|
||||
}
|
||||
|
||||
}else if(transaction.isPurchasTransaction()) {
|
||||
this.totalSharesApproved += transaction.getTotalShares() ;
|
||||
if(this.totalSharesApproved == null) {
|
||||
this.totalSharesApproved = transaction.getTotalShares() ;
|
||||
}else {
|
||||
this.totalSharesApproved += transaction.getTotalShares() ;
|
||||
}
|
||||
}
|
||||
|
||||
this.shareAccountTransactions.add(transaction);
|
||||
@@ -337,6 +346,10 @@ public class ShareAccount extends AbstractPersistable<Long> {
|
||||
return this.client.getDisplayName();
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return this.client ;
|
||||
}
|
||||
|
||||
public String getSavingsAccountNo() {
|
||||
return this.savingsAccount.getAccountNumber();
|
||||
}
|
||||
@@ -501,6 +514,10 @@ public class ShareAccount extends AbstractPersistable<Long> {
|
||||
return this.client.getOffice().getId();
|
||||
}
|
||||
|
||||
public void setTotalPendingShares(final Long shares) {
|
||||
this.totalSharesPending = shares ;
|
||||
}
|
||||
|
||||
public ShareAccountTransaction getShareAccountTransaction(final ShareAccountTransaction transaction) {
|
||||
ShareAccountTransaction returnTrans = null;
|
||||
for (ShareAccountTransaction tran : this.shareAccountTransactions) {
|
||||
@@ -549,4 +566,12 @@ public class ShareAccount extends AbstractPersistable<Long> {
|
||||
public PeriodFrequencyType getLockinPeriodFrequencyType() {
|
||||
return this.lockinPeriodFrequencyType ;
|
||||
}
|
||||
|
||||
public Date getActivatedDate() {
|
||||
return this.activatedDate ;
|
||||
}
|
||||
|
||||
public Integer status() {
|
||||
return this.status ;
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -239,6 +239,10 @@ public class ShareAccountTransaction extends AbstractPersistable<Long> {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTransactionDate(final Date transactionDate) {
|
||||
this.transactionDate = transactionDate ;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return this.active ;
|
||||
}
|
||||
|
||||
+64
-44
@@ -57,6 +57,7 @@ import org.apache.fineract.portfolio.savings.service.SavingsAccountReadPlatformS
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccount;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountCharge;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountChargePaidBy;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountStatusType;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountTransaction;
|
||||
import org.apache.fineract.portfolio.shareproducts.domain.ShareProduct;
|
||||
import org.apache.fineract.portfolio.shareproducts.domain.ShareProductRepositoryWrapper;
|
||||
@@ -287,37 +288,56 @@ public class ShareAccountDataSerializer {
|
||||
}
|
||||
|
||||
Date existingApplicationDate = null ;
|
||||
List<ShareAccountTransaction> purchaseTransactionsList = new ArrayList<>() ;
|
||||
Set<ShareAccountCharge> chargesList = new HashSet<>() ;
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.requestedshares_paramname, element)
|
||||
|| this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.charges_paramname, element)) {
|
||||
Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
|
||||
List<Long> reveralIds = new ArrayList<>();
|
||||
for (ShareAccountTransaction transaction : transactions) {
|
||||
transaction.setActive(false);
|
||||
if(!transaction.isChargeTransaction()) {
|
||||
existingApplicationDate = transaction.getPurchasedDate() ;
|
||||
if (transaction.isActive()) {
|
||||
reveralIds.add(transaction.getId());
|
||||
transaction.setActive(false);
|
||||
if (!transaction.isChargeTransaction()) {
|
||||
existingApplicationDate = transaction.getPurchasedDate();
|
||||
ShareAccountTransaction newtransaction = new ShareAccountTransaction(transaction.getPurchasedDate(),
|
||||
transaction.getTotalShares(), transaction.getPurchasePrice());
|
||||
purchaseTransactionsList.add(newtransaction);
|
||||
}
|
||||
}
|
||||
reveralIds.add(transaction.getId());
|
||||
}
|
||||
|
||||
actualChanges.put("reversalIds", reveralIds);
|
||||
Set<ShareAccountCharge> charges = account.getCharges() ;
|
||||
for(ShareAccountCharge charge: charges) {
|
||||
charge.setActive(false);
|
||||
if(charge.isActive()) {
|
||||
charge.setActive(false);
|
||||
ChargeTimeType chargeTime = null;
|
||||
ChargeCalculationType chargeCalculation = null;
|
||||
Boolean status = Boolean.TRUE;
|
||||
ShareAccountCharge accountCharge = ShareAccountCharge.createNewWithoutShareAccount(charge.getCharge(), charge.percentageOrAmount(), chargeTime,
|
||||
chargeCalculation, status);
|
||||
chargesList.add(accountCharge) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.requestedshares_paramname, element)) {
|
||||
Long requestedShares = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element);
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(requestedShares).notNull();
|
||||
Date applicationDate = null ;
|
||||
purchaseTransactionsList.clear() ;
|
||||
if(this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.applicationdate_param, element)) {
|
||||
applicationDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.applicationdate_param, element)
|
||||
.toDate();
|
||||
.toDate();
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.applicationdate_param).value(applicationDate).notNull();
|
||||
}else {
|
||||
applicationDate = existingApplicationDate ;
|
||||
}
|
||||
BigDecimal unitPrice = shareProduct.deriveMarketPrice(applicationDate);
|
||||
ShareAccountTransaction transaction = new ShareAccountTransaction(applicationDate, requestedShares, unitPrice);
|
||||
account.addTransaction(transaction);
|
||||
purchaseTransactionsList.add(transaction) ;
|
||||
actualChanges.put(ShareAccountApiConstants.requestedshares_paramname, "Transaction");
|
||||
|
||||
if(shareProduct.getMinimumClientShares() != null && requestedShares < shareProduct.getMinimumClientShares()) {
|
||||
@@ -329,13 +349,14 @@ public class ShareAccountDataSerializer {
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(requestedShares)
|
||||
.failWithCode("client.can.not.purchase.shares.morethan.product.definition", "Client can not purchase shares more than product definition");
|
||||
}
|
||||
}/*else if(this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.charges_paramname, element)) {
|
||||
//Since we are removing all purchase transactions when either charge param or requestedShares param exists
|
||||
for(ShareAccountTransaction transaction:existingTransactions) {
|
||||
account.addTransaction(transaction);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
if(!purchaseTransactionsList.isEmpty()) {
|
||||
ShareAccountTransaction transaction = purchaseTransactionsList.get(0) ;
|
||||
account.addTransaction(transaction);
|
||||
account.setTotalPendingShares(transaction.getTotalShares());
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.allowdividendcalculationforinactiveclients_paramname, element)) {
|
||||
Boolean allowdividendsForInactiveClients = this.fromApiJsonHelper.extractBooleanNamed(
|
||||
ShareAccountApiConstants.allowdividendcalculationforinactiveclients_paramname, element);
|
||||
@@ -381,17 +402,20 @@ public class ShareAccountDataSerializer {
|
||||
if (this.fromApiJsonHelper.parameterExists(ShareAccountApiConstants.charges_paramname, element)) {
|
||||
shareProduct = account.getShareProduct();
|
||||
final MonetaryCurrency currency = shareProduct.getCurrency();
|
||||
Set<ShareAccountCharge> charges = assembleListOfAccountCharges(element, currency.getCode());
|
||||
if (charges != null) {
|
||||
for (ShareAccountCharge charge : charges) {
|
||||
charge.update(account);
|
||||
}
|
||||
account.addCharges(charges);
|
||||
if (!charges.isEmpty()) {
|
||||
chargesList = assembleListOfAccountCharges(element, currency.getCode());
|
||||
if (chargesList != null) {
|
||||
if (!chargesList.isEmpty()) {
|
||||
actualChanges.put(ShareAccountApiConstants.charges_paramname, new HashSet<ShareAccountCharge>());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(chargesList != null && !chargesList.isEmpty()) {
|
||||
for (ShareAccountCharge charge : chargesList) {
|
||||
charge.update(account);
|
||||
}
|
||||
account.addCharges(chargesList);
|
||||
}
|
||||
|
||||
createChargeTransaction(account);
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
return actualChanges;
|
||||
@@ -406,6 +430,9 @@ public class ShareAccountDataSerializer {
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("sharesaccount");
|
||||
JsonElement element = jsonCommand.parsedJson();
|
||||
if(!account.status().equals(ShareAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.getValue())) {
|
||||
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.pending.for.approval");
|
||||
}
|
||||
LocalDate approvedDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.approveddate_paramname, element);
|
||||
final LocalDate submittalDate = new LocalDate(account.getSubmittedDate());
|
||||
if (approvedDate != null && approvedDate.isBefore(submittalDate)) {
|
||||
@@ -470,23 +497,15 @@ public class ShareAccountDataSerializer {
|
||||
public Map<String, Object> validateAndUndoApprove(JsonCommand jsonCommand, ShareAccount account) {
|
||||
Map<String, Object> actualChanges = new HashMap<>();
|
||||
if (StringUtils.isBlank(jsonCommand.json())) { throw new InvalidJsonException(); }
|
||||
// final Type typeOfMap = new TypeToken<Map<String, Object>>()
|
||||
// {}.getType();
|
||||
// this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap,
|
||||
// jsonCommand.json(), ShareAccountApiConstants.activateParameters);
|
||||
// final List<ApiParameterError> dataValidationErrors = new
|
||||
// ArrayList<>();
|
||||
// final DataValidatorBuilder baseDataValidator = new
|
||||
// DataValidatorBuilder(dataValidationErrors).resource("sharesaccount");
|
||||
// JsonElement element = jsonCommand.parsedJson();
|
||||
// String notes =
|
||||
// this.fromApiJsonHelper.extractStringNamed(ShareAccountApiConstants.note_paramname,
|
||||
// element);
|
||||
// baseDataValidator.reset().parameter(ShareAccountApiConstants.approveddate_paramname).validateDateAfter(account.get)
|
||||
// AppUser approvedUser =
|
||||
// this.platformSecurityContext.authenticatedUser();
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(), ShareAccountApiConstants.activateParameters);
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("sharesaccount");
|
||||
if(!account.status().equals(ShareAccountStatusType.APPROVED.getValue())) {
|
||||
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.in.approved.status");
|
||||
}
|
||||
account.undoApprove();
|
||||
updateTotalChargeDerivedForUndoApproval(account) ;
|
||||
updateTotalChargeDerivedForUndoApproval(account);
|
||||
actualChanges.put(ShareAccountApiConstants.charges_paramname, Boolean.TRUE);
|
||||
return actualChanges;
|
||||
}
|
||||
@@ -537,6 +556,9 @@ public class ShareAccountDataSerializer {
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("sharesaccount");
|
||||
JsonElement element = jsonCommand.parsedJson();
|
||||
if(!account.status().equals(ShareAccountStatusType.APPROVED.getValue())) {
|
||||
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.in.approved.status");
|
||||
}
|
||||
LocalDate activatedDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.activatedate_paramname, element);
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.activatedate_paramname).value(activatedDate).notNull();
|
||||
final LocalDate approvedDate = new LocalDate(account.getApprovedDate());
|
||||
@@ -565,6 +587,7 @@ public class ShareAccountDataSerializer {
|
||||
Set<ShareAccountTransaction> transactions = account.getChargeTransactions();
|
||||
for (ShareAccountTransaction transaction : transactions) {
|
||||
if (transaction.isChargeTransaction()) {
|
||||
transaction.updateTransactionDate(account.getActivatedDate());
|
||||
transaction.updateAmountPaid(transaction.amount());
|
||||
}
|
||||
}
|
||||
@@ -614,6 +637,9 @@ public class ShareAccountDataSerializer {
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("sharesaccount");
|
||||
JsonElement element = jsonCommand.parsedJson();
|
||||
if(!account.status().equals(ShareAccountStatusType.ACTIVE.getValue())) {
|
||||
baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.in.active.state") ;
|
||||
}
|
||||
LocalDate requestedDate = this.fromApiJsonHelper.extractLocalDateNamed(ShareAccountApiConstants.requesteddate_paramname, element);
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requesteddate_paramname).value(requestedDate).notNull();
|
||||
final Long sharesRequested = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element);
|
||||
@@ -775,11 +801,6 @@ public class ShareAccountDataSerializer {
|
||||
final Long sharesRequested = this.fromApiJsonHelper.extractLongNamed(ShareAccountApiConstants.requestedshares_paramname, element);
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.requestedshares_paramname).value(sharesRequested).notNull()
|
||||
.longGreaterThanZero();
|
||||
|
||||
final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(element.getAsJsonObject());
|
||||
final BigDecimal unitPrice = this.fromApiJsonHelper.extractBigDecimalNamed(ShareAccountApiConstants.purchasedprice_paramname,
|
||||
element, locale);
|
||||
baseDataValidator.reset().parameter(ShareAccountApiConstants.purchasedprice_paramname).value(unitPrice).notNull().positiveAmount();
|
||||
boolean isTransactionBeforeExistingTransactions = false ;
|
||||
Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions() ;
|
||||
for(ShareAccountTransaction transaction: transactions) {
|
||||
@@ -797,6 +818,7 @@ public class ShareAccountDataSerializer {
|
||||
.failWithCodeNoParameterAddedToErrorCode("redeem.transaction.date.cannot.be.before.existing.transactions");
|
||||
}
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
BigDecimal unitPrice = account.getShareProduct().deriveMarketPrice(requestedDate.toDate()) ;
|
||||
ShareAccountTransaction transaction = ShareAccountTransaction.createRedeemTransaction(requestedDate.toDate(), sharesRequested,
|
||||
unitPrice);
|
||||
validateRedeemRequest(account, transaction, baseDataValidator, dataValidationErrors) ;
|
||||
@@ -949,8 +971,6 @@ public class ShareAccountDataSerializer {
|
||||
account.close(closedDate.toDate(), approvedUser);
|
||||
handleRedeemSharesChargeTransactions(account, transaction);
|
||||
actualChanges.put(ShareAccountApiConstants.requestedshares_paramname, transaction);
|
||||
updateTotalChargeDerived(account);
|
||||
|
||||
return actualChanges;
|
||||
}
|
||||
}
|
||||
|
||||
+34
-15
@@ -30,10 +30,13 @@ import java.util.Set;
|
||||
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
|
||||
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.infrastructure.core.service.Page;
|
||||
import org.apache.fineract.infrastructure.core.service.PaginationHelper;
|
||||
import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
|
||||
import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
||||
import org.apache.fineract.portfolio.accountdetails.data.ShareAccountSummaryData;
|
||||
import org.apache.fineract.portfolio.accounts.constants.AccountsApiConstants;
|
||||
import org.apache.fineract.portfolio.accounts.constants.ShareAccountApiConstants;
|
||||
import org.apache.fineract.portfolio.accounts.data.AccountData;
|
||||
import org.apache.fineract.portfolio.charge.data.ChargeData;
|
||||
import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService;
|
||||
@@ -45,17 +48,16 @@ import org.apache.fineract.portfolio.products.service.ProductReadPlatformService
|
||||
import org.apache.fineract.portfolio.savings.DepositAccountType;
|
||||
import org.apache.fineract.portfolio.savings.data.SavingsAccountData;
|
||||
import org.apache.fineract.portfolio.savings.service.SavingsAccountReadPlatformService;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountTransactionData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountApplicationTimelineData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountDividendData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountStatusEnumData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountChargeData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountDividendData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountStatusEnumData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountTransactionData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.PurchasedSharesStatusType;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountStatusType;
|
||||
import org.apache.fineract.portfolio.shareproducts.SharePeriodFrequencyType;
|
||||
import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceData;
|
||||
import org.apache.fineract.portfolio.shareproducts.data.ShareProductData;
|
||||
import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceData;
|
||||
import org.apache.fineract.portfolio.shareproducts.service.ShareProductDropdownReadPlatformService;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
@@ -78,7 +80,8 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat
|
||||
private final PurchasedSharesReadPlatformService purchasedSharesReadPlatformService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
|
||||
|
||||
private final PaginationHelper<AccountData> shareAccountDataPaginationHelper = new PaginationHelper<>();
|
||||
|
||||
@Autowired
|
||||
public ShareAccountReadPlatformServiceImpl(final RoutingDataSource dataSource, final ApplicationContext applicationContext,
|
||||
final ChargeReadPlatformService chargeReadPlatformService,
|
||||
@@ -148,7 +151,7 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat
|
||||
|
||||
ShareAccountMapper mapper = new ShareAccountMapper(charges, purchasedShares);
|
||||
String query = "select " + mapper.schema() + "where sa.id=?";
|
||||
ShareAccountData data = this.jdbcTemplate.queryForObject(query, mapper, new Object[] { id });
|
||||
ShareAccountData data = (ShareAccountData)this.jdbcTemplate.queryForObject(query, mapper, new Object[] { id });
|
||||
String serviceName = "share" + ProductsApiConstants.READPLATFORM_NAME;
|
||||
ProductReadPlatformService service = (ProductReadPlatformService) this.applicationContext.getBean(serviceName);
|
||||
final ShareProductData productData = (ShareProductData) service.retrieveOne(data.getProductId(), false);
|
||||
@@ -179,13 +182,30 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AccountData> retrieveAll() {
|
||||
return null;
|
||||
public Page<AccountData> retrieveAll(final Integer offSet, final Integer limit) {
|
||||
final Collection<ShareAccountChargeData> charges = null ;
|
||||
final Collection<ShareAccountTransactionData> purchasedShares = null ;
|
||||
ShareAccountMapper mapper = new ShareAccountMapper(charges, purchasedShares) ;
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
sqlBuilder.append("select SQL_CALC_FOUND_ROWS ");
|
||||
sqlBuilder.append(mapper.schema());
|
||||
sqlBuilder.append(" where sa.status_enum = ? ");
|
||||
if (limit != null) {
|
||||
sqlBuilder.append(" limit ").append(limit);
|
||||
}
|
||||
if (offSet != null) {
|
||||
sqlBuilder.append(" offset ").append(offSet);
|
||||
}
|
||||
|
||||
final String sqlCountRows = "SELECT FOUND_ROWS()";
|
||||
Object[] whereClauseItemsitems = new Object[] {ShareAccountStatusType.ACTIVE.getValue()};
|
||||
return this.shareAccountDataPaginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(),
|
||||
whereClauseItemsitems, mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getResponseDataParams() {
|
||||
return null;
|
||||
return ShareAccountApiConstants.supportedParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,7 +242,7 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat
|
||||
return savingsCharges;
|
||||
}
|
||||
|
||||
private final static class ShareAccountMapper implements RowMapper<ShareAccountData> {
|
||||
private final static class ShareAccountMapper implements RowMapper<AccountData> {
|
||||
|
||||
private final Collection<ShareAccountChargeData> charges;
|
||||
private final Collection<ShareAccountTransactionData> purchasedShares;
|
||||
@@ -328,16 +348,14 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat
|
||||
|
||||
final Integer lockinPeriodFrequencyTypeValue = JdbcSupport.getInteger(rs, "lockinPeriodEnum");
|
||||
if (lockinPeriodFrequencyTypeValue != null) {
|
||||
final SharePeriodFrequencyType lockinPeriodType = SharePeriodFrequencyType.fromInt(lockinPeriodFrequencyTypeValue);
|
||||
lockinPeriodFrequencyType = SharesEnumerations.lockinPeriodFrequencyType(lockinPeriodType);
|
||||
lockinPeriodFrequencyType = SharesEnumerations.lockinPeriodFrequencyType(lockinPeriodFrequencyTypeValue);
|
||||
}
|
||||
|
||||
final Integer minimumActivePeriod = JdbcSupport.getInteger(rs, "minimumactivePeriod");
|
||||
EnumOptionData minimumActivePeriodType = null;
|
||||
final Integer minimumActivePeriodTypeValue = JdbcSupport.getInteger(rs, "minimumactivePeriodEnum");
|
||||
if (minimumActivePeriodTypeValue != null) {
|
||||
final SharePeriodFrequencyType minmumPeriodType = SharePeriodFrequencyType.fromInt(minimumActivePeriodTypeValue);
|
||||
minimumActivePeriodType = SharesEnumerations.lockinPeriodFrequencyType(minmumPeriodType);
|
||||
minimumActivePeriodType = SharesEnumerations.minimumActivePeriodFrequencyType(minimumActivePeriodTypeValue);
|
||||
}
|
||||
|
||||
final String shortProductName = null;
|
||||
@@ -467,6 +485,7 @@ public class ShareAccountReadPlatformServiceImpl implements ShareAccountReadPlat
|
||||
schema = buff.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Override
|
||||
public ShareAccountDividendData mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
final Long id = rs.getLong("id");
|
||||
|
||||
+33
-1
@@ -27,6 +27,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.fineract.accounting.journalentry.service.JournalEntryWritePlatformService;
|
||||
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormat;
|
||||
import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormatRepositoryWrapper;
|
||||
@@ -39,6 +40,8 @@ import org.apache.fineract.organisation.monetary.data.CurrencyData;
|
||||
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
|
||||
import org.apache.fineract.portfolio.accounts.constants.ShareAccountApiConstants;
|
||||
import org.apache.fineract.portfolio.client.domain.AccountNumberGenerator;
|
||||
import org.apache.fineract.portfolio.note.domain.Note;
|
||||
import org.apache.fineract.portfolio.note.domain.NoteRepository;
|
||||
import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountTransactionEnumData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccount;
|
||||
import org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountChargePaidBy;
|
||||
@@ -67,19 +70,23 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
|
||||
|
||||
private final JournalEntryWritePlatformService journalEntryWritePlatformService;
|
||||
|
||||
private final NoteRepository noteRepository;
|
||||
|
||||
@Autowired
|
||||
public ShareAccountWritePlatformServiceJpaRepositoryImpl(final ShareAccountDataSerializer accountDataSerializer,
|
||||
final ShareAccountRepositoryWrapper shareAccountRepository,
|
||||
final ShareProductRepositoryWrapper shareProductRepository,
|
||||
final AccountNumberGenerator accountNumberGenerator,
|
||||
final AccountNumberFormatRepositoryWrapper accountNumberFormatRepository,
|
||||
final JournalEntryWritePlatformService journalEntryWritePlatformService) {
|
||||
final JournalEntryWritePlatformService journalEntryWritePlatformService,
|
||||
final NoteRepository noteRepository) {
|
||||
this.accountDataSerializer = accountDataSerializer;
|
||||
this.shareAccountRepository = shareAccountRepository;
|
||||
this.shareProductRepository = shareProductRepository ;
|
||||
this.accountNumberGenerator = accountNumberGenerator;
|
||||
this.accountNumberFormatRepository = accountNumberFormatRepository;
|
||||
this.journalEntryWritePlatformService = journalEntryWritePlatformService;
|
||||
this.noteRepository = noteRepository ;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,6 +188,7 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
|
||||
this.journalEntryWritePlatformService.revertShareAccountJournalEntries(reversalIds, transactionDate);
|
||||
journalEntryWritePlatformService.createJournalEntriesForShares(populateJournalEntries(account,
|
||||
account.getPendingForApprovalSharePurchaseTransactions()));
|
||||
changes.remove("reversalIds") ;
|
||||
}
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(jsonCommand.commandId()) //
|
||||
@@ -231,6 +239,12 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
|
||||
Map<String, Object> changes = this.accountDataSerializer.validateAndApprove(jsonCommand, account);
|
||||
if (!changes.isEmpty()) {
|
||||
this.shareAccountRepository.save(account);
|
||||
final String noteText = jsonCommand.stringValueOfParameterNamed("note");
|
||||
if (StringUtils.isNotBlank(noteText)) {
|
||||
final Note note = Note.shareNote(account, noteText);
|
||||
changes.put("note", noteText);
|
||||
this.noteRepository.save(note);
|
||||
}
|
||||
}
|
||||
Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
|
||||
Set<ShareAccountTransaction> journalTransactions = new HashSet<>();
|
||||
@@ -265,6 +279,12 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
|
||||
Map<String, Object> changes = this.accountDataSerializer.validateAndReject(jsonCommand, account);
|
||||
if (!changes.isEmpty()) {
|
||||
this.shareAccountRepository.save(account);
|
||||
final String noteText = jsonCommand.stringValueOfParameterNamed("note");
|
||||
if (StringUtils.isNotBlank(noteText)) {
|
||||
final Note note = Note.shareNote(account, noteText);
|
||||
changes.put("note", noteText);
|
||||
this.noteRepository.save(note);
|
||||
}
|
||||
}
|
||||
Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions();
|
||||
Set<ShareAccountTransaction> journalTransactions = new HashSet<>();
|
||||
@@ -293,6 +313,12 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
|
||||
Map<String, Object> changes = this.accountDataSerializer.validateAndUndoApprove(jsonCommand, account);
|
||||
if (!changes.isEmpty()) {
|
||||
this.shareAccountRepository.save(account);
|
||||
final String noteText = jsonCommand.stringValueOfParameterNamed("note");
|
||||
if (StringUtils.isNotBlank(noteText)) {
|
||||
final Note note = Note.shareNote(account, noteText);
|
||||
changes.put("note", noteText);
|
||||
this.noteRepository.save(note);
|
||||
}
|
||||
}
|
||||
|
||||
Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions() ;
|
||||
@@ -447,6 +473,12 @@ public class ShareAccountWritePlatformServiceJpaRepositoryImpl implements ShareA
|
||||
Map<String, Object> changes = this.accountDataSerializer.validateAndClose(jsonCommand, account);
|
||||
if (!changes.isEmpty()) {
|
||||
this.shareAccountRepository.save(account);
|
||||
final String noteText = jsonCommand.stringValueOfParameterNamed("note");
|
||||
if (StringUtils.isNotBlank(noteText)) {
|
||||
final Note note = Note.shareNote(account, noteText);
|
||||
changes.put("note", noteText);
|
||||
this.noteRepository.save(note);
|
||||
}
|
||||
ShareAccountTransaction transaction = (ShareAccountTransaction) changes
|
||||
.get(ShareAccountApiConstants.requestedshares_paramname);
|
||||
transaction = account.getShareAccountTransaction(transaction);
|
||||
|
||||
+32
-1
@@ -121,8 +121,39 @@ public class SharesEnumerations {
|
||||
return lockinPeriodFrequencyType(SharePeriodFrequencyType.fromInt(id));
|
||||
}
|
||||
|
||||
public static EnumOptionData minimumActivePeriodFrequencyType(final int id) {
|
||||
return minimumActivePeriodFrequencyType(SharePeriodFrequencyType.fromInt(id));
|
||||
}
|
||||
|
||||
public static EnumOptionData minimumActivePeriodFrequencyType(final SharePeriodFrequencyType type) {
|
||||
final String codePrefix = "shares.minimumactive." ;
|
||||
EnumOptionData optionData = new EnumOptionData(SharePeriodFrequencyType.INVALID.getValue().longValue(),
|
||||
SharePeriodFrequencyType.INVALID.getCode(), "Invalid");
|
||||
switch (type) {
|
||||
case INVALID:
|
||||
break;
|
||||
case DAYS:
|
||||
optionData = new EnumOptionData(SharePeriodFrequencyType.DAYS.getValue().longValue(), codePrefix
|
||||
+ SharePeriodFrequencyType.DAYS.getCode(), "Days");
|
||||
break;
|
||||
case WEEKS:
|
||||
optionData = new EnumOptionData(SharePeriodFrequencyType.WEEKS.getValue().longValue(), codePrefix
|
||||
+ SharePeriodFrequencyType.WEEKS.getCode(), "Weeks");
|
||||
break;
|
||||
case MONTHS:
|
||||
optionData = new EnumOptionData(SharePeriodFrequencyType.MONTHS.getValue().longValue(), codePrefix
|
||||
+ SharePeriodFrequencyType.MONTHS.getCode(), "Months");
|
||||
break;
|
||||
case YEARS:
|
||||
optionData = new EnumOptionData(SharePeriodFrequencyType.YEARS.getValue().longValue(), codePrefix
|
||||
+ SharePeriodFrequencyType.YEARS.getCode(), "Years");
|
||||
break;
|
||||
}
|
||||
return optionData;
|
||||
}
|
||||
|
||||
public static EnumOptionData lockinPeriodFrequencyType(final SharePeriodFrequencyType type) {
|
||||
final String codePrefix = "savings.lockin.";
|
||||
final String codePrefix = "shares.lockin." ;
|
||||
EnumOptionData optionData = new EnumOptionData(SharePeriodFrequencyType.INVALID.getValue().longValue(),
|
||||
SharePeriodFrequencyType.INVALID.getCode(), "Invalid");
|
||||
switch (type) {
|
||||
|
||||
+2
-1
@@ -172,6 +172,7 @@ public class ShareProductDataSerializer {
|
||||
sharesIssued, unitPrice, shareCapitalValue, minimumClientShares, nominalClientShares, maximumClientShares, marketPriceSet,
|
||||
charges, allowdividendsForInactiveClients, lockinPeriod, lockPeriodType, minimumActivePeriod, minimumActivePeriodType,
|
||||
createdBy, createdDate, modifiedBy, modifiedOn, accountingRuleType);
|
||||
|
||||
for (ShareProductMarketPrice data : marketPriceSet) {
|
||||
data.setShareProduct(product);
|
||||
}
|
||||
@@ -204,7 +205,7 @@ public class ShareProductDataSerializer {
|
||||
}
|
||||
|
||||
private Set<ShareProductMarketPrice> asembleShareMarketPrice(final JsonElement element) {
|
||||
Set<ShareProductMarketPrice> set = null;
|
||||
Set<ShareProductMarketPrice> set = new HashSet<>();
|
||||
if (this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.marketprice_paramname, element)) {
|
||||
set = new HashSet<>();
|
||||
JsonArray array = this.fromApiJsonHelper.extractJsonArrayNamed(ShareProductApiConstants.marketprice_paramname, element);
|
||||
|
||||
+12
-7
@@ -45,9 +45,9 @@ import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService;
|
||||
import org.apache.fineract.portfolio.products.data.ProductData;
|
||||
import org.apache.fineract.portfolio.products.exception.ProductNotFoundException;
|
||||
import org.apache.fineract.portfolio.products.service.ProductReadPlatformService;
|
||||
import org.apache.fineract.portfolio.savings.service.SavingsEnumerations;
|
||||
import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceData;
|
||||
import org.apache.fineract.portfolio.shareaccounts.service.SharesEnumerations;
|
||||
import org.apache.fineract.portfolio.shareproducts.data.ShareProductData;
|
||||
import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -63,7 +63,7 @@ public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformS
|
||||
private final ShareProductDropdownReadPlatformService shareProductDropdownReadPlatformService;
|
||||
private final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService;
|
||||
private final ProductToGLAccountMappingReadPlatformService accountMappingReadPlatformService;
|
||||
private final PaginationHelper<ProductData> provisioningEntryDataPaginationHelper = new PaginationHelper<>();
|
||||
private final PaginationHelper<ProductData> shareProductDataPaginationHelper = new PaginationHelper<>();
|
||||
|
||||
@Autowired
|
||||
public ShareProductReadPlatformServiceImpl(final RoutingDataSource dataSource,
|
||||
@@ -81,7 +81,9 @@ public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformS
|
||||
|
||||
@Override
|
||||
public Page<ProductData> retrieveAllProducts(Integer offSet, Integer limit) {
|
||||
AllShareProductRowMapper mapper = new AllShareProductRowMapper();
|
||||
final Collection<ShareProductMarketPriceData> shareMarketCollection = null ;
|
||||
final Collection<ChargeData> charges = null ;
|
||||
ShareProductRowMapper mapper = new ShareProductRowMapper(shareMarketCollection, charges);
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
sqlBuilder.append("select SQL_CALC_FOUND_ROWS ");
|
||||
sqlBuilder.append(mapper.schema());
|
||||
@@ -94,7 +96,7 @@ public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformS
|
||||
|
||||
final String sqlCountRows = "SELECT FOUND_ROWS()";
|
||||
Object[] whereClauseItemsitems = new Object[] {};
|
||||
return this.provisioningEntryDataPaginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(),
|
||||
return this.shareProductDataPaginationHelper.fetchPage(this.jdbcTemplate, sqlCountRows, sqlBuilder.toString(),
|
||||
whereClauseItemsitems, mapper);
|
||||
}
|
||||
|
||||
@@ -168,6 +170,7 @@ public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformS
|
||||
|
||||
private static final class AllShareProductRowMapper implements RowMapper<ProductData> {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Override
|
||||
public ShareProductData mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
final Long id = rs.getLong("id");
|
||||
@@ -184,6 +187,7 @@ public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformS
|
||||
|
||||
private static final class MarketPriceRowMapper implements RowMapper<ShareProductMarketPriceData> {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Override
|
||||
public ShareProductMarketPriceData mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
final Long id = rs.getLong("id");
|
||||
@@ -226,6 +230,7 @@ public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformS
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Override
|
||||
public ShareProductData mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
final Long id = rs.getLong("id");
|
||||
@@ -258,14 +263,14 @@ public class ShareProductReadPlatformServiceImpl implements ProductReadPlatformS
|
||||
final Integer minimumActviePeriodEnumValue = JdbcSupport.getInteger(rs, "minimum_active_period_frequency_enum");
|
||||
EnumOptionData minimumActivePeriodType = null;
|
||||
if (minimumActviePeriodEnumValue != null) {
|
||||
minimumActivePeriodType = SavingsEnumerations.lockinPeriodFrequencyType(minimumActviePeriodEnumValue);
|
||||
minimumActivePeriodType = SharesEnumerations.minimumActivePeriodFrequencyType(minimumActviePeriodEnumValue);
|
||||
}
|
||||
|
||||
final Integer lockinPeriodFrequency = JdbcSupport.getInteger(rs, "lockin_period_frequency");
|
||||
EnumOptionData lockinPeriodFrequencyType = null;
|
||||
final Integer lockinPeriodFrequencyTypeValue = JdbcSupport.getInteger(rs, "lockin_period_frequency_enum");
|
||||
if (lockinPeriodFrequencyTypeValue != null) {
|
||||
lockinPeriodFrequencyType = SavingsEnumerations.lockinPeriodFrequencyType(lockinPeriodFrequencyTypeValue);
|
||||
lockinPeriodFrequencyType = SharesEnumerations.lockinPeriodFrequencyType(lockinPeriodFrequencyTypeValue);
|
||||
}
|
||||
final Integer accountingRuleId = JdbcSupport.getInteger(rs, "accountingType");
|
||||
final EnumOptionData accountingRuleType = AccountingEnumerations.accountingRuleType(accountingRuleId);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `m_note`
|
||||
ADD COLUMN `share_account_id` BIGINT(20) NULL DEFAULT NULL AFTER `savings_account_transaction_id`;
|
||||
Reference in New Issue
Block a user