diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java index f2aec7c3b..19681440c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/DepositAccountsApiResource.java @@ -197,23 +197,23 @@ public class DepositAccountsApiResource { EntityIdentifier identifier = this.depositAccountWritePlatformService.approveDepositApplication(command); response = Response.ok().entity(identifier).build(); } - else if (is(commandParam, "reject")) { - DepositStateTransitionCommand command=apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId, jsonRequestBody); - EntityIdentifier identifier = this.depositAccountWritePlatformService.rejectDepositApplication(command); - response = Response.ok().entity(identifier).build(); - } else if (is(commandParam, "withdrewbyclient")) { - DepositStateTransitionCommand command=apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId, jsonRequestBody); - EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command); - response = Response.ok().entity(identifier).build(); - } + else{ + DepositStateTransitionCommand command=apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId, jsonRequestBody); + if (is(commandParam, "reject")) { + EntityIdentifier identifier = this.depositAccountWritePlatformService.rejectDepositApplication(command); + response = Response.ok().entity(identifier).build(); + } else if (is(commandParam, "withdrewbyclient")) { + EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command); + response = Response.ok().entity(identifier).build(); + } - UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId); - - if (is(commandParam, "undoapproval")) { - EntityIdentifier identifier = this.depositAccountWritePlatformService.undoDepositApproval(undoCommand); - response = Response.ok().entity(identifier).build(); - } + UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote()); + if (is(commandParam, "undoapproval")) { + EntityIdentifier identifier = this.depositAccountWritePlatformService.undoDepositApproval(undoCommand); + response = Response.ok().entity(identifier).build(); + } + } if (response == null) { throw new UnrecognizedQueryParamException("command", commandParam); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositStateTransitionApprovalCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositStateTransitionApprovalCommand.java index b7654ee4c..4b7987d49 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositStateTransitionApprovalCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositStateTransitionApprovalCommand.java @@ -13,8 +13,10 @@ public class DepositStateTransitionApprovalCommand { private final Integer tenureInMonths; private final Integer interestCompoundedEveryPeriodType; private final Integer interestCompoundedEvery; + + private final String note; - public DepositStateTransitionApprovalCommand(Long resourceIdentifier, Long productId, LocalDate eventDate, Integer tenureInMonths, BigDecimal depositAmount, Integer interestCompoundedEveryPeriodType, Integer interestCompoundedEvery) { + public DepositStateTransitionApprovalCommand(Long resourceIdentifier, Long productId, LocalDate eventDate, Integer tenureInMonths, BigDecimal depositAmount, Integer interestCompoundedEveryPeriodType, Integer interestCompoundedEvery, String note) { this.accountId=resourceIdentifier; this.eventDate=eventDate; @@ -24,6 +26,8 @@ public class DepositStateTransitionApprovalCommand { this.productId=productId; this.interestCompoundedEvery=interestCompoundedEvery; + this.note = note; + } public Long getAccountId() { @@ -53,5 +57,9 @@ public class DepositStateTransitionApprovalCommand { public Integer getInterestCompoundedEvery() { return interestCompoundedEvery; } + + public String getNote() { + return note; + } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositStateTransitionCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositStateTransitionCommand.java index 4aab88736..a9d985870 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositStateTransitionCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/DepositStateTransitionCommand.java @@ -7,9 +7,12 @@ public class DepositStateTransitionCommand { private final Long accountId; private final LocalDate eventDate; - public DepositStateTransitionCommand(final Long accountId, final LocalDate enentDate) { + private final String note; + + public DepositStateTransitionCommand(final Long accountId, final LocalDate enentDate, final String note) { this.accountId=accountId; this.eventDate=enentDate; + this.note = note; } public Long getAccountId() { @@ -19,5 +22,9 @@ public class DepositStateTransitionCommand { public LocalDate getEventDate() { return eventDate; } + + public String getNote() { + return note; + } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UndoStateTransitionCommand.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UndoStateTransitionCommand.java index c1c7e6a85..6f321982a 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UndoStateTransitionCommand.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/commands/UndoStateTransitionCommand.java @@ -13,11 +13,6 @@ public class UndoStateTransitionCommand { this.note = note; } - public UndoStateTransitionCommand(final Long loanId) { - this.loanId = loanId; - this.note=null; - } - public Long getLoanId() { return this.loanId; } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java index 4622aa0b4..edc594336 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/ApiDataConversionServiceImpl.java @@ -1105,15 +1105,16 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { Type typeOfMap = new TypeToken>(){}.getType(); Map requestMap = gsonConverter.fromJson(json, typeOfMap); - Set supportedParams = new HashSet( Arrays.asList("eventDate", "dateFormat")); + Set supportedParams = new HashSet( Arrays.asList("eventDate", "dateFormat", "note")); checkForUnsupportedParameters(requestMap, supportedParams); Set modifiedParameters = new HashSet(); LocalDate eventDate = extractLocalDateParameter("eventDate", requestMap, modifiedParameters); + String note =extractStringParameter("note", requestMap, modifiedParameters); - return new DepositStateTransitionCommand(resourceIdentifier, eventDate); + return new DepositStateTransitionCommand(resourceIdentifier, eventDate, note); } @Override @@ -1127,7 +1128,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { Type typeOfMap = new TypeToken>(){}.getType(); Map requestMap = gsonConverter.fromJson(json, typeOfMap); - Set supportedParams = new HashSet(Arrays.asList("locale","commencementDate", "dateFormat", "tenureInMonths", "deposit", "interestCompoundedEveryPeriodType", "productId","interestCompoundedEvery")); + Set supportedParams = new HashSet(Arrays.asList("locale","commencementDate", "dateFormat", "tenureInMonths", "deposit", "interestCompoundedEveryPeriodType", "productId","interestCompoundedEvery","note")); checkForUnsupportedParameters(requestMap, supportedParams); @@ -1139,7 +1140,8 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService { Integer interestCompoundedEveryPeriodType = extractIntegerParameter("interestCompoundedEveryPeriodType", requestMap, modifiedParameters); Integer interestCompoundedEvery = extractIntegerParameter("interestCompoundedEvery", requestMap, modifiedParameters); Long productId = extractLongParameter("productId", requestMap, modifiedParameters); + String note = extractStringParameter("note", requestMap, modifiedParameters); - return new DepositStateTransitionApprovalCommand(resourceIdentifier, productId, commencementDate, tenureInMonths, deposit, interestCompoundedEveryPeriodType,interestCompoundedEvery); + return new DepositStateTransitionApprovalCommand(resourceIdentifier, productId, commencementDate, tenureInMonths, deposit, interestCompoundedEveryPeriodType,interestCompoundedEvery, note); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/Note.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/Note.java index 7be4b0f04..3306bae0a 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/Note.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/Note.java @@ -9,6 +9,7 @@ import javax.persistence.Table; import org.mifosng.platform.infrastructure.AbstractAuditableCustom; import org.mifosng.platform.loan.domain.Loan; import org.mifosng.platform.loan.domain.LoanTransaction; +import org.mifosng.platform.saving.domain.DepositAccount; import org.mifosng.platform.user.domain.AppUser; @Entity @@ -37,8 +38,12 @@ public class Note extends AbstractAuditableCustom { @Column(name = "note_type_enum") private Integer noteTypeId; + @ManyToOne + @JoinColumn(name = "deposit_account_id", nullable = true) + private DepositAccount depositAccount; + public enum NoteType { - CLIENT(100, "noteType.client"), LOAN(200, "noteType.loan"), LOAN_TRANSACTION(300, "noteType.loan.transaction"); + CLIENT(100, "noteType.client"), LOAN(200, "noteType.loan"), LOAN_TRANSACTION(300, "noteType.loan.transaction"), DEPOSIT(400, "noteType.deposit"); private Integer value; private String code; @@ -104,6 +109,13 @@ public class Note extends AbstractAuditableCustom { this.noteTypeId = null; } + public Note(DepositAccount account, String note) { + this.depositAccount=account; + this.client = account.client(); + this.note = note; + this.noteTypeId = NoteType.DEPOSIT.getValue(); + } + public void update(final String note) { this.note = note; } @@ -111,4 +123,8 @@ public class Note extends AbstractAuditableCustom { public boolean isNotAgainstClientWithIdOf(Long clientId) { return !this.client.identifiedBy(clientId); } + + public static Note depositNote(DepositAccount account, String noteText) { + return new Note(account,noteText); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/NoteEnumerations.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/NoteEnumerations.java index dba8639a6..804ee579f 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/NoteEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/domain/NoteEnumerations.java @@ -21,6 +21,11 @@ public class NoteEnumerations { case LOAN_TRANSACTION: optionData = new EnumOptionData(type.getValue().longValue(), type.getCode(), "Loan transaction note"); break; + case DEPOSIT: + optionData = new EnumOptionData(type.getValue().longValue(), type.getCode(), "Deposit transaction note"); + break; + default: + break; } return optionData; } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java index 686ef3dab..b52240294 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/domain/DepositAccount.java @@ -370,4 +370,8 @@ public class DepositAccount extends AbstractAuditableCustom { public Money getDeposit() { return Money.of(this.currency, this.depositAmount); } + + public Client client() { + return this.client; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java index 1ef791d0a..18c35acc1 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java @@ -3,12 +3,15 @@ package org.mifosng.platform.saving.service; import java.util.Arrays; import java.util.List; +import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; import org.mifosng.platform.api.commands.DepositAccountCommand; import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand; import org.mifosng.platform.api.commands.DepositStateTransitionCommand; import org.mifosng.platform.api.commands.UndoStateTransitionCommand; import org.mifosng.platform.api.data.EntityIdentifier; +import org.mifosng.platform.client.domain.Note; +import org.mifosng.platform.client.domain.NoteRepository; import org.mifosng.platform.exceptions.DepositAccountNotFoundException; import org.mifosng.platform.exceptions.NoAuthorizationException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException; @@ -37,18 +40,21 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo private final DepositAccountRepository depositAccountRepository; private final DepositAccountAssembler depositAccountAssembler; private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator; + private final NoteRepository noteRepository; @Autowired public DepositAccountWritePlatformServiceJpaRepositoryImpl( final PlatformSecurityContext context, final DepositAccountRepository depositAccountRepository, final DepositAccountAssembler depositAccountAssembler, - final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator + final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator, + final NoteRepository noteRepository ) { this.context=context; this.depositAccountRepository = depositAccountRepository; this.depositAccountAssembler = depositAccountAssembler; this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator; + this.noteRepository = noteRepository; } /* @@ -126,6 +132,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.depositAccountRepository.save(account); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.depositNote(account, noteText); + this.noteRepository.save(note); + } + return new EntityIdentifier(account.getId()); @@ -160,6 +172,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo account.reject(eventDate, defaultDepositLifecycleStateMachine()); this.depositAccountRepository.save(account); + + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.depositNote(account, noteText); + this.noteRepository.save(note); + } return new EntityIdentifier(account.getId()); } @@ -184,6 +202,14 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } account.withdrawnByApplicant(eventDate, defaultDepositLifecycleStateMachine()); + this.depositAccountRepository.save(account); + + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.depositNote(account, noteText); + this.noteRepository.save(note); + } + return new EntityIdentifier(account.getId()); } @@ -201,6 +227,11 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo account.undoDepositApproval(defaultDepositLifecycleStateMachine()); this.depositAccountRepository.save(account); + String noteText = command.getNote(); + if (StringUtils.isNotBlank(noteText)) { + Note note = Note.depositNote(account, noteText); + this.noteRepository.save(note); + } return new EntityIdentifier(account.getId()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositStateTransitionApprovalCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositStateTransitionApprovalCommandValidator.java index 35291184e..9b1c27b66 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositStateTransitionApprovalCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositStateTransitionApprovalCommandValidator.java @@ -23,12 +23,14 @@ public class DepositStateTransitionApprovalCommandValidator { List dataValidationErrors = new ArrayList(); DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.transition"); baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); - baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull(); + baseDataValidator.reset().parameter("commencementDate").value(command.getEventDate()).notNull(); baseDataValidator.reset().parameter("depositAmount").value(command.getDepositAmount()).ignoreIfNull().zeroOrPositiveAmount(); baseDataValidator.reset().parameter("tenureInMonths").value(command.getTenureInMonths()).ignoreIfNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(command.getInterestCompoundedEveryPeriodType()).ignoreIfNull().inMinMaxRange(2, 2); + baseDataValidator.reset().parameter("note").value(command.getNote()).notNull(); + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositStateTransitionCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositStateTransitionCommandValidator.java index 7d5f96f59..d4cf549bf 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositStateTransitionCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/saving/service/DepositStateTransitionCommandValidator.java @@ -22,6 +22,7 @@ public class DepositStateTransitionCommandValidator { DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.transition"); baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull(); + baseDataValidator.reset().parameter("note").value(command.getNote()).notNull(); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);