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-accounting.git
commit 2c738b5a2b558bb5a369d8e8d85171d6524fe82f Author: mgeiss <[email protected]> AuthorDate: Tue Oct 3 10:43:27 2017 +0200 add alternative account numbers to support legacy migration --- .../client/JournalEntryAlreadyExistsException.java | 15 +++++++++++++++ .../accounting/api/v1/client/LedgerManager.java | 19 +++++++++++++++++-- .../io/mifos/accounting/api/v1/domain/Account.java | 9 +++++++++ .../main/java/io/mifos/accounting/TestAccount.java | 20 ++++++++++++++++++++ .../command/handler/AccountCommandHandler.java | 1 + .../service/internal/mapper/AccountMapper.java | 1 + .../service/internal/repository/AccountEntity.java | 10 ++++++++++ .../specification/AccountSpecification.java | 3 ++- .../mariadb/V8__alternative_account_number.sql | 19 +++++++++++++++++++ 9 files changed, 94 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/io/mifos/accounting/api/v1/client/JournalEntryAlreadyExistsException.java b/api/src/main/java/io/mifos/accounting/api/v1/client/JournalEntryAlreadyExistsException.java index c79b69b..5fe9267 100644 --- a/api/src/main/java/io/mifos/accounting/api/v1/client/JournalEntryAlreadyExistsException.java +++ b/api/src/main/java/io/mifos/accounting/api/v1/client/JournalEntryAlreadyExistsException.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.accounting.api.v1.client; public class JournalEntryAlreadyExistsException extends RuntimeException { diff --git a/api/src/main/java/io/mifos/accounting/api/v1/client/LedgerManager.java b/api/src/main/java/io/mifos/accounting/api/v1/client/LedgerManager.java index 93fe6ce..8a9177e 100644 --- a/api/src/main/java/io/mifos/accounting/api/v1/client/LedgerManager.java +++ b/api/src/main/java/io/mifos/accounting/api/v1/client/LedgerManager.java @@ -15,14 +15,29 @@ */ package io.mifos.accounting.api.v1.client; -import io.mifos.accounting.api.v1.domain.*; +import io.mifos.accounting.api.v1.domain.Account; +import io.mifos.accounting.api.v1.domain.AccountCommand; +import io.mifos.accounting.api.v1.domain.AccountEntry; +import io.mifos.accounting.api.v1.domain.AccountEntryPage; +import io.mifos.accounting.api.v1.domain.AccountPage; +import io.mifos.accounting.api.v1.domain.ChartOfAccountEntry; +import io.mifos.accounting.api.v1.domain.JournalEntry; +import io.mifos.accounting.api.v1.domain.Ledger; +import io.mifos.accounting.api.v1.domain.LedgerPage; +import io.mifos.accounting.api.v1.domain.TransactionType; +import io.mifos.accounting.api.v1.domain.TransactionTypePage; +import io.mifos.accounting.api.v1.domain.TrialBalance; import io.mifos.core.api.annotation.ThrowsException; import io.mifos.core.api.annotation.ThrowsExceptions; import io.mifos.core.api.util.CustomFeignClientsConfiguration; import org.springframework.cloud.netflix.feign.FeignClient; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import javax.validation.Valid; import java.math.BigDecimal; diff --git a/api/src/main/java/io/mifos/accounting/api/v1/domain/Account.java b/api/src/main/java/io/mifos/accounting/api/v1/domain/Account.java index b3c466a..2faf14a 100644 --- a/api/src/main/java/io/mifos/accounting/api/v1/domain/Account.java +++ b/api/src/main/java/io/mifos/accounting/api/v1/domain/Account.java @@ -40,6 +40,7 @@ public final class Account { @ValidIdentifier private String ledger; private State state; + private String alternativeAccountNumber; private String createdOn; private String createdBy; private String lastModifiedOn; @@ -124,6 +125,14 @@ public final class Account { this.state = State.valueOf(state); } + public String getAlternativeAccountNumber() { + return this.alternativeAccountNumber; + } + + public void setAlternativeAccountNumber(final String alternativeAccountNumber) { + this.alternativeAccountNumber = alternativeAccountNumber; + } + public String getCreatedOn() { return this.createdOn; } diff --git a/component-test/src/main/java/io/mifos/accounting/TestAccount.java b/component-test/src/main/java/io/mifos/accounting/TestAccount.java index 342ae53..1c827c5 100644 --- a/component-test/src/main/java/io/mifos/accounting/TestAccount.java +++ b/component-test/src/main/java/io/mifos/accounting/TestAccount.java @@ -643,4 +643,24 @@ public class TestAccount extends AbstractAccountingTest { Assert.assertEquals(2L, accountPage.getTotalElements().longValue()); } + @Test + public void shouldFindAccountWithAlternativeAccountNumber() throws Exception { + final Ledger ledger = LedgerGenerator.createLedger("alt-account-10000", AccountType.EQUITY); + + this.testSubject.createLedger(ledger); + this.eventRecorder.wait(EventConstants.POST_LEDGER, ledger.getIdentifier()); + + final Account altAccount = + AccountGenerator.createAccount(ledger.getIdentifier(), "alt-account-10001", AccountType.EQUITY); + altAccount.setAlternativeAccountNumber("08154711"); + this.testSubject.createAccount(altAccount); + this.eventRecorder.wait(EventConstants.POST_ACCOUNT, altAccount.getIdentifier()); + + final AccountPage accountPage = this.testSubject.fetchAccounts(true, "08154711", null, true, + 0, 10, null, null); + Assert.assertEquals(Long.valueOf(1L), accountPage.getTotalElements()); + final Account account = accountPage.getAccounts().get(0); + Assert.assertEquals("alt-account-10001", account.getIdentifier()); + Assert.assertEquals("08154711", account.getAlternativeAccountNumber()); + } } diff --git a/service/src/main/java/io/mifos/accounting/service/internal/command/handler/AccountCommandHandler.java b/service/src/main/java/io/mifos/accounting/service/internal/command/handler/AccountCommandHandler.java index c06de37..f0bab24 100644 --- a/service/src/main/java/io/mifos/accounting/service/internal/command/handler/AccountCommandHandler.java +++ b/service/src/main/java/io/mifos/accounting/service/internal/command/handler/AccountCommandHandler.java @@ -126,6 +126,7 @@ public class AccountCommandHandler { accountEntity.setBalance(account.getBalance()); accountEntity.setState(Account.State.OPEN.name()); + accountEntity.setAlternativeAccountNumber(account.getAlternativeAccountNumber()); accountEntity.setCreatedBy(UserContextHolder.checkedGetUser()); accountEntity.setCreatedOn(LocalDateTime.now(Clock.systemUTC())); diff --git a/service/src/main/java/io/mifos/accounting/service/internal/mapper/AccountMapper.java b/service/src/main/java/io/mifos/accounting/service/internal/mapper/AccountMapper.java index 237fc99..2030d05 100644 --- a/service/src/main/java/io/mifos/accounting/service/internal/mapper/AccountMapper.java +++ b/service/src/main/java/io/mifos/accounting/service/internal/mapper/AccountMapper.java @@ -51,6 +51,7 @@ public class AccountMapper { account.setReferenceAccount(accountEntity.getReferenceAccount().getIdentifier()); } account.setBalance(accountEntity.getBalance()); + account.setAlternativeAccountNumber(accountEntity.getAlternativeAccountNumber()); account.setCreatedBy(accountEntity.getCreatedBy()); account.setCreatedOn(DateConverter.toIsoString(accountEntity.getCreatedOn())); if (accountEntity.getLastModifiedBy() != null) { diff --git a/service/src/main/java/io/mifos/accounting/service/internal/repository/AccountEntity.java b/service/src/main/java/io/mifos/accounting/service/internal/repository/AccountEntity.java index c7816cb..4dd85b1 100644 --- a/service/src/main/java/io/mifos/accounting/service/internal/repository/AccountEntity.java +++ b/service/src/main/java/io/mifos/accounting/service/internal/repository/AccountEntity.java @@ -58,6 +58,8 @@ public class AccountEntity { private LedgerEntity ledger; @Column(name = "a_state") private String state; + @Column(name = "alternative_account_number", length = 256, nullable = true) + private String alternativeAccountNumber; @Column(name = "created_on") @Convert(converter = LocalDateTimeConverter.class) private LocalDateTime createdOn; @@ -153,6 +155,14 @@ public class AccountEntity { this.state = state; } + public String getAlternativeAccountNumber() { + return this.alternativeAccountNumber; + } + + public void setAlternativeAccountNumber(final String alternativeAccountNumber) { + this.alternativeAccountNumber = alternativeAccountNumber; + } + public LocalDateTime getCreatedOn() { return this.createdOn; } diff --git a/service/src/main/java/io/mifos/accounting/service/internal/repository/specification/AccountSpecification.java b/service/src/main/java/io/mifos/accounting/service/internal/repository/specification/AccountSpecification.java index bdbbf91..6ffb19d 100644 --- a/service/src/main/java/io/mifos/accounting/service/internal/repository/specification/AccountSpecification.java +++ b/service/src/main/java/io/mifos/accounting/service/internal/repository/specification/AccountSpecification.java @@ -49,7 +49,8 @@ public class AccountSpecification { predicates.add( cb.or( cb.like(root.get("identifier"), likeExpression), - cb.like(root.get("name"), likeExpression) + cb.like(root.get("name"), likeExpression), + cb.like(root.get("alternativeAccountNumber"), likeExpression) ) ); } diff --git a/service/src/main/resources/db/migrations/mariadb/V8__alternative_account_number.sql b/service/src/main/resources/db/migrations/mariadb/V8__alternative_account_number.sql new file mode 100644 index 0000000..0d9f9a5 --- /dev/null +++ b/service/src/main/resources/db/migrations/mariadb/V8__alternative_account_number.sql @@ -0,0 +1,19 @@ +-- +-- 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. +-- + +ALTER TABLE thoth_accounts ADD COLUMN alternative_account_number VARCHAR(256) NULL; + +ALTER TABLE thoth_accounts ADD CONSTRAINT thoth_alt_acct_no_uq UNIQUE (alternative_account_number); \ No newline at end of file -- To stop receiving notification emails like this one, please contact [email protected].
