add notes for deposit events

This commit is contained in:
Madhukar
2012-09-12 15:25:24 +05:30
parent 79d2e8bea8
commit 3e7724a8c3
11 changed files with 100 additions and 29 deletions
@@ -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);
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
@@ -1105,15 +1105,16 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>( Arrays.asList("eventDate", "dateFormat"));
Set<String> supportedParams = new HashSet<String>( Arrays.asList("eventDate", "dateFormat", "note"));
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
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<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(Arrays.asList("locale","commencementDate", "dateFormat", "tenureInMonths", "deposit", "interestCompoundedEveryPeriodType", "productId","interestCompoundedEvery"));
Set<String> supportedParams = new HashSet<String>(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);
}
}
@@ -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<AppUser, Long> {
@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<AppUser, Long> {
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<AppUser, Long> {
public boolean isNotAgainstClientWithIdOf(Long clientId) {
return !this.client.identifiedBy(clientId);
}
public static Note depositNote(DepositAccount account, String noteText) {
return new Note(account,noteText);
}
}
@@ -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;
}
@@ -370,4 +370,8 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
public Money getDeposit() {
return Money.of(this.currency, this.depositAmount);
}
public Client client() {
return this.client;
}
}
@@ -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());
}
}
@@ -23,12 +23,14 @@ public class DepositStateTransitionApprovalCommandValidator {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
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);
}
@@ -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);