Skip to content
Permalink
Browse files
Merge pull request #7 from markusgeiss/develop
enhancement and fixes
  • Loading branch information
markusgeiss committed Sep 7, 2017
2 parents 383584b + 84e054a commit 74f815acf055a8de2e3197d5b2a842a866fc20f7
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 33 deletions.
@@ -15,6 +15,7 @@
*/
package io.mifos.teller.api.v1.domain;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;

@@ -23,7 +24,8 @@ public class Charge {
private String code;
private String incomeAccountIdentifier;
private String name;
@DecimalMin(value = "0.00")
@DecimalMin(value = "0.001")
@DecimalMax(value = "9999999999.99999")
private BigDecimal amount;

public Charge() {
@@ -18,6 +18,7 @@
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.Valid;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@@ -32,7 +33,8 @@ public class Cheque {
@NotEmpty
private String payee;
@NotNull
@DecimalMin(value = "0.00", inclusive = false)
@DecimalMin(value = "0.001")
@DecimalMax(value = "9999999999.99999")
private BigDecimal amount;
@NotEmpty
private String dateIssued;
@@ -38,10 +38,12 @@ public enum State {
@DecimalMin("0.00")
@DecimalMax("1000000000.00")
private BigDecimal cashdrawLimit;
@ValidIdentifier
@ValidIdentifier(maxLength = 34)
private String tellerAccountIdentifier;
@ValidIdentifier
@ValidIdentifier(maxLength = 34)
private String vaultAccountIdentifier;
@ValidIdentifier(maxLength = 34)
private String chequesReceivableAccount;
private String assignedEmployee;
private State state;
private String createdBy;
@@ -93,6 +95,14 @@ public void setVaultAccountIdentifier(final String vaultAccountIdentifier) {
this.vaultAccountIdentifier = vaultAccountIdentifier;
}

public String getChequesReceivableAccount() {
return this.chequesReceivableAccount;
}

public void setChequesReceivableAccount(final String chequesReceivableAccount) {
this.chequesReceivableAccount = chequesReceivableAccount;
}

public String getAssignedEmployee() {
return this.assignedEmployee;
}
@@ -15,14 +15,16 @@
*/
package io.mifos.teller.api.v1.domain;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;
import java.util.List;

public class TellerBalanceSheet {

private String day;
@DecimalMin("0.00")
@DecimalMin(value = "0.001")
@DecimalMax(value = "9999999999.99999")
private BigDecimal balance;
private List<TellerEntry> entries;

@@ -15,6 +15,7 @@
*/
package io.mifos.teller.api.v1.domain;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;

@@ -28,7 +29,8 @@ public enum Type {
private Type type;
private String transactionDate;
private String message;
@DecimalMin("0.00")
@DecimalMin(value = "0.001")
@DecimalMax(value = "9999999999.99999")
private BigDecimal amount;

public TellerEntry() {
@@ -17,6 +17,7 @@

import io.mifos.core.lang.validation.constraints.ValidIdentifier;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@@ -39,6 +40,7 @@ public enum Adjustment {
@NotNull
private Adjustment adjustment;
@DecimalMin("0.00")
@DecimalMax("9999999999.99999")
private BigDecimal amount;
@ValidIdentifier(optional = true)
private String assignedEmployeeIdentifier;
@@ -18,6 +18,7 @@
import io.mifos.core.lang.validation.constraints.ValidIdentifier;

import javax.validation.Valid;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@@ -42,14 +43,15 @@ public enum State {
private String productIdentifier;
@ValidIdentifier(optional = true)
private String productCaseIdentifier;
@ValidIdentifier
@ValidIdentifier(maxLength = 34)
private String customerAccountIdentifier;
@ValidIdentifier(optional = true)
@ValidIdentifier(maxLength = 34, optional = true)
private String targetAccountIdentifier;
@ValidIdentifier
private String clerk;
@NotNull
@DecimalMin(value = "0.00", inclusive = false)
@DecimalMin(value = "0.000")
@DecimalMax(value = "9999999999.99999")
private BigDecimal amount;
private State state;
@Valid
@@ -15,14 +15,16 @@
*/
package io.mifos.teller.api.v1.domain;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;
import java.util.List;

public class TellerTransactionCosts {

private String tellerTransactionIdentifier;
@DecimalMin("0.00")
@DecimalMin(value = "0.001")
@DecimalMax(value = "9999999999.99999")
private BigDecimal totalAmount;
private List<Charge> charges;

@@ -160,7 +160,75 @@ public void shouldCloseAccount() throws Exception {
tellerTransaction.setCustomerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
tellerTransaction.setAmount(commonAmount);
tellerTransaction.setAmount(this.commonAmount);

final Account account = new Account();
account.setBalance(this.commonAmount.doubleValue());
account.setState(Account.State.OPEN.name());
Mockito.doAnswer(invocation -> Optional.of(account))
.when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
Mockito.doAnswer(invocation -> Collections.emptyList())
.when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
Mockito.doAnswer(invocation -> Collections.emptyList())
.when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());

super.testSubject.post(teller.getCode(), tellerTransaction);
}

@Test
public void shouldCloseAccountZeroBalance() throws Exception {
final Teller teller = this.prepareTeller();

final UnlockDrawerCommand unlockDrawerCommand = new UnlockDrawerCommand();
unlockDrawerCommand.setEmployeeIdentifier(AbstractTellerTest.TEST_USER);
unlockDrawerCommand.setPassword(teller.getPassword());

super.testSubject.unlockDrawer(teller.getCode(), unlockDrawerCommand);

super.eventRecorder.wait(EventConstants.AUTHENTICATE_TELLER, teller.getCode());

final TellerTransaction tellerTransaction = new TellerTransaction();
tellerTransaction.setTransactionType(ServiceConstants.TX_CLOSE_ACCOUNT);
tellerTransaction.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
tellerTransaction.setProductIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
tellerTransaction.setAmount(BigDecimal.ZERO);

final Account account = new Account();
account.setBalance(0.00D);
account.setState(Account.State.OPEN.name());
Mockito.doAnswer(invocation -> Optional.of(account))
.when(super.accountingServiceSpy).findAccount(tellerTransaction.getCustomerAccountIdentifier());
Mockito.doAnswer(invocation -> Collections.emptyList())
.when(super.depositAccountManagementServiceSpy).getCharges(Matchers.eq(tellerTransaction));
Mockito.doAnswer(invocation -> Collections.emptyList())
.when(super.depositAccountManagementServiceSpy).fetchProductInstances(tellerTransaction.getCustomerIdentifier());

super.testSubject.post(teller.getCode(), tellerTransaction);
}

@Test(expected = TransactionProcessingException.class)
public void shouldNotCloseAccountRemainingBalance() throws Exception {
final Teller teller = this.prepareTeller();

final UnlockDrawerCommand unlockDrawerCommand = new UnlockDrawerCommand();
unlockDrawerCommand.setEmployeeIdentifier(AbstractTellerTest.TEST_USER);
unlockDrawerCommand.setPassword(teller.getPassword());

super.testSubject.unlockDrawer(teller.getCode(), unlockDrawerCommand);

super.eventRecorder.wait(EventConstants.AUTHENTICATE_TELLER, teller.getCode());

final TellerTransaction tellerTransaction = new TellerTransaction();
tellerTransaction.setTransactionType(ServiceConstants.TX_CLOSE_ACCOUNT);
tellerTransaction.setTransactionDate(DateConverter.toIsoString(LocalDateTime.now(Clock.systemUTC())));
tellerTransaction.setProductIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setCustomerIdentifier(RandomStringUtils.randomAlphanumeric(32));
tellerTransaction.setClerk(AbstractTellerTest.TEST_USER);
tellerTransaction.setAmount(this.commonAmount);

final Account account = new Account();
account.setBalance(2000.00D);
@@ -30,8 +30,9 @@ public static Teller createRandomTeller() {
final Teller teller = new Teller();
teller.setCode(RandomStringUtils.randomAlphanumeric(32));
teller.setPassword(RandomStringUtils.randomAlphanumeric(12));
teller.setTellerAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
teller.setVaultAccountIdentifier(RandomStringUtils.randomAlphanumeric(32));
teller.setTellerAccountIdentifier(RandomStringUtils.randomAlphanumeric(34));
teller.setVaultAccountIdentifier(RandomStringUtils.randomAlphanumeric(34));
teller.setChequesReceivableAccount(RandomStringUtils.randomAlphanumeric(34));
teller.setCashdrawLimit(BigDecimal.valueOf(10000L));

return teller;
@@ -124,6 +124,7 @@ public String process(final ChangeTellerCommand changeTellerCommand) {

tellerEntity.setTellerAccountIdentifier(teller.getTellerAccountIdentifier());
tellerEntity.setVaultAccountIdentifier(teller.getVaultAccountIdentifier());
tellerEntity.setChequesReceivableAccount(teller.getChequesReceivableAccount());
tellerEntity.setCashdrawLimit(teller.getCashdrawLimit());
tellerEntity.setLastModifiedBy(UserContextHolder.checkedGetUser());
tellerEntity.setLastModifiedOn(LocalDateTime.now(Clock.systemUTC()));
@@ -32,6 +32,7 @@ public static Teller map(final TellerEntity tellerEntity) {
teller.setVaultAccountIdentifier(tellerEntity.getVaultAccountIdentifier());
teller.setCashdrawLimit(tellerEntity.getCashdrawLimit());
teller.setAssignedEmployee(tellerEntity.getAssignedEmployeeIdentifier());
teller.setChequesReceivableAccount(tellerEntity.getChequesReceivableAccount());
teller.setState(tellerEntity.getState());
if (tellerEntity.getCreatedBy() != null) {
teller.setCreatedBy(tellerEntity.getCreatedBy());
@@ -52,6 +53,7 @@ public static TellerEntity map(final String officeIdentifier, final Teller telle
tellerEntity.setOfficeIdentifier(officeIdentifier);
tellerEntity.setTellerAccountIdentifier(teller.getTellerAccountIdentifier());
tellerEntity.setVaultAccountIdentifier(teller.getVaultAccountIdentifier());
tellerEntity.setChequesReceivableAccount(teller.getChequesReceivableAccount());
tellerEntity.setCashdrawLimit(teller.getCashdrawLimit());
tellerEntity.setAssignedEmployeeIdentifier(teller.getAssignedEmployee());
if (teller.getState() != null) {
@@ -19,13 +19,16 @@
import io.mifos.teller.ServiceConstants;
import io.mifos.teller.api.v1.domain.TellerTransaction;
import io.mifos.teller.service.internal.mapper.ChequeMapper;
import io.mifos.teller.service.internal.repository.TellerEntity;
import io.mifos.teller.service.internal.repository.TellerRepository;
import io.mifos.teller.service.internal.service.helper.ChequeService;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class ChequeTransactionHandler {

@@ -42,8 +45,11 @@ public ChequeTransactionHandler(@Qualifier(ServiceConstants.LOGGER_NAME) final L
this.tellerRepository = tellerRepository;
}

public void processCheque(final TellerTransaction tellerTransaction) {
public void processCheque(final String tellerCode, final TellerTransaction tellerTransaction) {
final Optional<TellerEntity> optionalTeller = this.tellerRepository.findByIdentifier(tellerCode);
final ChequeTransaction chequeTransaction = new ChequeTransaction();
optionalTeller.ifPresent(tellerEntity ->
chequeTransaction.setChequesReceivableAccount(tellerEntity.getChequesReceivableAccount()));
chequeTransaction.setCreditorAccountNumber(tellerTransaction.getCustomerAccountIdentifier());
chequeTransaction.setCheque(ChequeMapper.map(tellerTransaction.getCheque()));

@@ -236,6 +236,7 @@ private Debtor createChargesDebtor(final String accountIdentifier, final TellerT
Double.valueOf(
tellerTransactionCosts.getCharges()
.stream()
.filter(charge -> charge.getAmount() != null && charge.getAmount().compareTo(BigDecimal.ZERO) > 0)
.mapToDouble(value -> value.getAmount().doubleValue())
.sum()
).toString()
@@ -247,6 +248,7 @@ private Debtor createChargesDebtor(final String accountIdentifier, final TellerT
private Set<Creditor> createChargeCreditors(final TellerTransactionCosts tellerTransactionCosts) {
return tellerTransactionCosts.getCharges()
.stream()
.filter(charge -> charge.getAmount() != null && charge.getAmount().compareTo(BigDecimal.ZERO) > 0)
.map(charge -> {
final Creditor chargeCreditor = new Creditor();
chargeCreditor.setAccountNumber(charge.getIncomeAccountIdentifier());
@@ -64,7 +64,7 @@ public void process(final String tellerCode, final TellerTransaction tellerTrans
this.portfolioTransactionHandler.processRepayment(tellerCode, tellerTransaction);
break;
case ServiceConstants.TX_CHEQUE:
this.chequeTransactionHandler.processCheque(tellerTransaction);
this.chequeTransactionHandler.processCheque(tellerCode, tellerTransaction);
break;
default:
throw new IllegalArgumentException("Unsupported TX type " + tellerTransaction.getTransactionType());
@@ -45,10 +45,12 @@ public class TellerEntity {
private String officeIdentifier;
@Column(name = "cashdraw_limit", nullable = false)
private BigDecimal cashdrawLimit;
@Column(name = "teller_account_identifier", nullable = false, length = 32)
@Column(name = "teller_account_identifier", nullable = false, length = 34)
private String tellerAccountIdentifier;
@Column(name = "vault_account_identifier", nullable = false, length = 32)
@Column(name = "vault_account_identifier", nullable = false, length = 34)
private String vaultAccountIdentifier;
@Column(name = "cheques_receivable_account", nullable = false, length = 34)
private String chequesReceivableAccount;
@Column(name = "assigned_employee_identifier", nullable = true, length = 32)
private String assignedEmployeeIdentifier;
@Column(name = "a_state", nullable = false, length = 256)
@@ -132,6 +134,14 @@ public void setVaultAccountIdentifier(final String vaultAccountIdentifier) {
this.vaultAccountIdentifier = vaultAccountIdentifier;
}

public String getChequesReceivableAccount() {
return this.chequesReceivableAccount;
}

public void setChequesReceivableAccount(final String chequesReceivableAccount) {
this.chequesReceivableAccount = chequesReceivableAccount;
}

public String getAssignedEmployeeIdentifier() {
return this.assignedEmployeeIdentifier;
}

0 comments on commit 74f815a

Please sign in to comment.