fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From my...@apache.org
Subject [fineract-cn-deposit-account-management] 15/26: added ability to use legacy account numbers
Date Mon, 22 Jan 2018 15:49:37 GMT
This is an automated email from the ASF dual-hosted git repository.

myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-deposit-account-management.git

commit 7b202a3404bac48ebb942742a50b0678b1d80530
Author: mgeiss <mgeiss@mifos.org>
AuthorDate: Tue Oct 3 11:02:45 2017 +0200

    added ability to use legacy account numbers
---
 .../main/java/io/mifos/deposit/TestActions.java    |  2 +-
 .../command/handler/ProductInstanceAggregate.java  | 37 +++++++++--------
 .../mapper/DividendDistributionMapper.java         |  1 -
 .../repository/ProductDefinitionCommandEntity.java |  1 -
 .../internal/service/helper/AccountingService.java | 47 +++++++++++-----------
 .../internal/service/helper/RhythmService.java     | 15 +++++++
 .../rest/ProductDefinitionRestController.java      |  1 -
 7 files changed, 58 insertions(+), 46 deletions(-)

diff --git a/component-test/src/main/java/io/mifos/deposit/TestActions.java b/component-test/src/main/java/io/mifos/deposit/TestActions.java
index 98fa6c7..680128e 100644
--- a/component-test/src/main/java/io/mifos/deposit/TestActions.java
+++ b/component-test/src/main/java/io/mifos/deposit/TestActions.java
@@ -46,7 +46,7 @@ public class TestActions extends AbstractDepositAccountManagementTest {
   }
 
   @Test(expected = ActionAlreadyExistsException.class)
-  public void shouldNoCreateActionAlreadyExists() throws Exception {
+  public void shouldNotCreateActionAlreadyExists() throws Exception {
     final Action action = Fixture.action();
     super.depositAccountManager.create(action);
 
diff --git a/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ProductInstanceAggregate.java
b/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ProductInstanceAggregate.java
index ac61c42..da6b8d7 100644
--- a/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ProductInstanceAggregate.java
+++ b/service/src/main/java/io/mifos/deposit/service/internal/command/handler/ProductInstanceAggregate.java
@@ -76,31 +76,30 @@ public class ProductInstanceAggregate {
     final ProductInstanceEntity productInstanceEntity =
         ProductInstanceMapper.map(productInstance, this.productDefinitionRepository);
 
-    if (productInstance.getAccountIdentifier() == null) {
-      final Optional<ProductDefinitionEntity> optionalProductDefinition =
-          productDefinitionRepository.findByIdentifier(productInstance.getProductIdentifier());
+    final Optional<ProductDefinitionEntity> optionalProductDefinition =
+        productDefinitionRepository.findByIdentifier(productInstance.getProductIdentifier());
 
-      optionalProductDefinition.ifPresent(productDefinitionEntity -> {
+    optionalProductDefinition.ifPresent(productDefinitionEntity -> {
 
-        final List<ProductInstanceEntity> currentProductInstances =
-            this.productInstanceRepository.findByCustomerIdentifier(productInstance.getCustomerIdentifier());
+      final List<ProductInstanceEntity> currentProductInstances =
+          this.productInstanceRepository.findByCustomerIdentifier(productInstance.getCustomerIdentifier());
 
-        final int accountSuffix = currentProductInstances.size() + 1;
-
-        final StringBuilder stringBuilder = new StringBuilder();
-        final String accountNumber = stringBuilder
-            .append(productInstance.getCustomerIdentifier())
-            .append(".")
-            .append(productDefinitionEntity.getEquityLedgerIdentifier())
-            .append(".")
-            .append(String.format("%05d", accountSuffix))
-            .toString();
+      final int accountSuffix = currentProductInstances.size() + 1;
+      final String accountNumber =
+          productInstance.getCustomerIdentifier() +
+              "." + productDefinitionEntity.getEquityLedgerIdentifier() +
+              "." + String.format("%05d", accountSuffix);
 
+      if (productInstance.getAccountIdentifier() == null) {
         productInstanceEntity.setAccountIdentifier(accountNumber);
+      } else {
+        productInstanceEntity.setAccountIdentifier(productInstance.getAccountIdentifier());
+      }
 
-        this.accountingService.createAccount(productDefinitionEntity, productInstanceEntity);
-      });
-    }
+      this.accountingService.createAccount(productDefinitionEntity.getEquityLedgerIdentifier(),
+          productDefinitionEntity.getName(), productInstanceEntity.getCustomerIdentifier(),
+          accountNumber, productInstance.getAccountIdentifier());
+    });
 
     productInstanceEntity.setCreatedBy(UserContextHolder.checkedGetUser());
     productInstanceEntity.setCreatedOn(LocalDateTime.now(Clock.systemUTC()));
diff --git a/service/src/main/java/io/mifos/deposit/service/internal/mapper/DividendDistributionMapper.java
b/service/src/main/java/io/mifos/deposit/service/internal/mapper/DividendDistributionMapper.java
index 6503836..1926606 100644
--- a/service/src/main/java/io/mifos/deposit/service/internal/mapper/DividendDistributionMapper.java
+++ b/service/src/main/java/io/mifos/deposit/service/internal/mapper/DividendDistributionMapper.java
@@ -16,7 +16,6 @@
 package io.mifos.deposit.service.internal.mapper;
 
 import io.mifos.core.api.util.UserContextHolder;
-import io.mifos.core.lang.DateConverter;
 import io.mifos.core.lang.DateOfBirth;
 import io.mifos.deposit.api.v1.definition.domain.DividendDistribution;
 import io.mifos.deposit.service.internal.repository.DividendDistributionEntity;
diff --git a/service/src/main/java/io/mifos/deposit/service/internal/repository/ProductDefinitionCommandEntity.java
b/service/src/main/java/io/mifos/deposit/service/internal/repository/ProductDefinitionCommandEntity.java
index 42208d7..1021080 100644
--- a/service/src/main/java/io/mifos/deposit/service/internal/repository/ProductDefinitionCommandEntity.java
+++ b/service/src/main/java/io/mifos/deposit/service/internal/repository/ProductDefinitionCommandEntity.java
@@ -17,7 +17,6 @@ package io.mifos.deposit.service.internal.repository;
 
 import io.mifos.core.mariadb.util.LocalDateTimeConverter;
 
-import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Convert;
 import javax.persistence.Entity;
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 2229a03..f23c932 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
@@ -15,24 +15,22 @@
  */
 package io.mifos.deposit.service.internal.service.helper;
 
+import com.google.common.collect.Lists;
 import io.mifos.accounting.api.v1.client.AccountNotFoundException;
 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.AccountEntry;
+import io.mifos.accounting.api.v1.domain.AccountPage;
 import io.mifos.accounting.api.v1.domain.JournalEntry;
 import io.mifos.accounting.api.v1.domain.Ledger;
 import io.mifos.core.lang.ServiceException;
 import io.mifos.deposit.service.ServiceConstants;
-import io.mifos.deposit.service.internal.repository.ProductDefinitionEntity;
-import io.mifos.deposit.service.internal.repository.ProductInstanceEntity;
-import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 
@@ -50,31 +48,27 @@ public class AccountingService {
     this.ledgerManager = ledgerManager;
   }
 
-  public void createAccount(final ProductDefinitionEntity productDefinitionEntity,
-                            final ProductInstanceEntity productInstanceEntity) {
-    final String ledgerIdentifier = productDefinitionEntity.getEquityLedgerIdentifier();
+  public void createAccount(final String equityLedger,
+                            final String productName,
+                            final String customer,
+                            final String accountNumber,
+                            final String alternativeAccountNumber) {
     try {
-      final Ledger ledger = this.ledgerManager.findLedger(ledgerIdentifier);
+      final Ledger ledger = this.ledgerManager.findLedger(equityLedger);
       final Account account = new Account();
-      account.setIdentifier(productInstanceEntity.getAccountIdentifier());
+      account.setIdentifier(accountNumber);
       account.setType(ledger.getType());
-      account.setLedger(ledgerIdentifier);
-      account.setName(productDefinitionEntity.getName());
-
-      account.setHolders(new HashSet<>(
-          Arrays.asList(productInstanceEntity.getCustomerIdentifier()))
-      );
-
-      if (productInstanceEntity.getBeneficiaries() != null) {
-        account.setSignatureAuthorities(new HashSet<>(
-            Arrays.asList(StringUtils.split(productInstanceEntity.getBeneficiaries(), ","))
-        ));
+      account.setLedger(equityLedger);
+      account.setName(productName);
+      account.setHolders(new HashSet<>(Lists.newArrayList(customer)));
+      account.setBalance(0.00D);
+      if (alternativeAccountNumber != null && !alternativeAccountNumber.equals(accountNumber))
{
+        account.setAlternativeAccountNumber(alternativeAccountNumber);
       }
 
-      account.setBalance(0.00D);
       this.ledgerManager.createAccount(account);
     } catch (final LedgerNotFoundException lnfex) {
-      throw ServiceException.notFound("Ledger {0} not found.", ledgerIdentifier);
+      throw ServiceException.notFound("Ledger {0} not found.", equityLedger);
     }
   }
 
@@ -82,7 +76,14 @@ public class AccountingService {
     try {
       return this.ledgerManager.findAccount(identifier);
     } catch (final AccountNotFoundException anfex) {
-      throw ServiceException.notFound("Account {0} not found.", identifier);
+      final AccountPage accountPage = this.ledgerManager.fetchAccounts(true, identifier,
null, true,
+          0, 10, null, null);
+
+      return accountPage.getAccounts()
+          .stream()
+          .filter(account -> account.getAlternativeAccountNumber().equals(identifier))
+          .findFirst()
+          .orElseThrow(() -> ServiceException.notFound("Account {0} not found.", identifier));
     }
   }
 
diff --git a/service/src/main/java/io/mifos/deposit/service/internal/service/helper/RhythmService.java
b/service/src/main/java/io/mifos/deposit/service/internal/service/helper/RhythmService.java
index dfa7d18..67349a0 100644
--- a/service/src/main/java/io/mifos/deposit/service/internal/service/helper/RhythmService.java
+++ b/service/src/main/java/io/mifos/deposit/service/internal/service/helper/RhythmService.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.deposit.service.internal.service.helper;
 
 import io.mifos.core.api.util.NotFoundException;
diff --git a/service/src/main/java/io/mifos/deposit/service/rest/ProductDefinitionRestController.java
b/service/src/main/java/io/mifos/deposit/service/rest/ProductDefinitionRestController.java
index dfd1c1f..c925e43 100644
--- a/service/src/main/java/io/mifos/deposit/service/rest/ProductDefinitionRestController.java
+++ b/service/src/main/java/io/mifos/deposit/service/rest/ProductDefinitionRestController.java
@@ -18,7 +18,6 @@ package io.mifos.deposit.service.rest;
 import io.mifos.anubis.annotation.AcceptedTokenType;
 import io.mifos.anubis.annotation.Permittable;
 import io.mifos.core.command.gateway.CommandGateway;
-import io.mifos.core.lang.DateConverter;
 import io.mifos.core.lang.ServiceException;
 import io.mifos.deposit.api.v1.PermittableGroupIds;
 import io.mifos.deposit.api.v1.definition.domain.DividendDistribution;

-- 
To stop receiving notification emails like this one, please contact
myrle@apache.org.

Mime
View raw message