handle account type ...
diff --git a/service/src/main/java/io/mifos/deposit/service/internal/service/helper/AccountingService.java b/service/src/main/java/io/mifos/deposit/service/internal/service/helper/AccountingService.java
index 3c68e87..fbd6b35 100644
--- a/service/src/main/java/io/mifos/deposit/service/internal/service/helper/AccountingService.java
+++ b/service/src/main/java/io/mifos/deposit/service/internal/service/helper/AccountingService.java
@@ -16,7 +16,10 @@
package io.mifos.deposit.service.internal.service.helper;
import io.mifos.accounting.api.v1.client.LedgerManager;
+import io.mifos.accounting.api.v1.client.LedgerNotFoundException;
import io.mifos.accounting.api.v1.domain.Account;
+import io.mifos.accounting.api.v1.domain.Ledger;
+import io.mifos.core.lang.ServiceException;
import io.mifos.deposit.service.ServiceConstants;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,11 +41,17 @@
}
public void createAccount(final String ledgerIdentifier, final String accountIdentifier, final String productName) {
- final Account account = new Account();
- account.setIdentifier(accountIdentifier);
- account.setLedger(ledgerIdentifier);
- account.setName(productName);
- account.setBalance(0.00D);
- this.ledgerManager.createAccount(account);
+ try {
+ final Ledger ledger = this.ledgerManager.findLedger(ledgerIdentifier);
+ final Account account = new Account();
+ account.setIdentifier(accountIdentifier);
+ account.setType(ledger.getType());
+ account.setLedger(ledgerIdentifier);
+ account.setName(productName);
+ account.setBalance(0.00D);
+ this.ledgerManager.createAccount(account);
+ } catch (final LedgerNotFoundException lnfex) {
+ throw ServiceException.notFound("Ledger {0} not found.", ledgerIdentifier);
+ }
}
}