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); EntityIdentifier identifier = this.depositAccountWritePlatformService.approveDepositApplication(command);
response = Response.ok().entity(identifier).build(); response = Response.ok().entity(identifier).build();
} }
else if (is(commandParam, "reject")) { else{
DepositStateTransitionCommand command=apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId, jsonRequestBody); DepositStateTransitionCommand command=apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId, jsonRequestBody);
EntityIdentifier identifier = this.depositAccountWritePlatformService.rejectDepositApplication(command); if (is(commandParam, "reject")) {
response = Response.ok().entity(identifier).build(); EntityIdentifier identifier = this.depositAccountWritePlatformService.rejectDepositApplication(command);
} else if (is(commandParam, "withdrewbyclient")) { response = Response.ok().entity(identifier).build();
DepositStateTransitionCommand command=apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId, jsonRequestBody); } else if (is(commandParam, "withdrewbyclient")) {
EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command); EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command);
response = Response.ok().entity(identifier).build(); response = Response.ok().entity(identifier).build();
} }
UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId); UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote());
if (is(commandParam, "undoapproval")) {
EntityIdentifier identifier = this.depositAccountWritePlatformService.undoDepositApproval(undoCommand);
response = Response.ok().entity(identifier).build();
}
if (is(commandParam, "undoapproval")) {
EntityIdentifier identifier = this.depositAccountWritePlatformService.undoDepositApproval(undoCommand);
response = Response.ok().entity(identifier).build();
}
}
if (response == null) { if (response == null) {
throw new UnrecognizedQueryParamException("command", commandParam); throw new UnrecognizedQueryParamException("command", commandParam);
} }
@@ -14,7 +14,9 @@ public class DepositStateTransitionApprovalCommand {
private final Integer interestCompoundedEveryPeriodType; private final Integer interestCompoundedEveryPeriodType;
private final Integer interestCompoundedEvery; private final Integer interestCompoundedEvery;
public DepositStateTransitionApprovalCommand(Long resourceIdentifier, Long productId, LocalDate eventDate, Integer tenureInMonths, BigDecimal depositAmount, Integer interestCompoundedEveryPeriodType, Integer interestCompoundedEvery) { private final String note;
public DepositStateTransitionApprovalCommand(Long resourceIdentifier, Long productId, LocalDate eventDate, Integer tenureInMonths, BigDecimal depositAmount, Integer interestCompoundedEveryPeriodType, Integer interestCompoundedEvery, String note) {
this.accountId=resourceIdentifier; this.accountId=resourceIdentifier;
this.eventDate=eventDate; this.eventDate=eventDate;
@@ -24,6 +26,8 @@ public class DepositStateTransitionApprovalCommand {
this.productId=productId; this.productId=productId;
this.interestCompoundedEvery=interestCompoundedEvery; this.interestCompoundedEvery=interestCompoundedEvery;
this.note = note;
} }
public Long getAccountId() { public Long getAccountId() {
@@ -54,4 +58,8 @@ public class DepositStateTransitionApprovalCommand {
return interestCompoundedEvery; return interestCompoundedEvery;
} }
public String getNote() {
return note;
}
} }
@@ -7,9 +7,12 @@ public class DepositStateTransitionCommand {
private final Long accountId; private final Long accountId;
private final LocalDate eventDate; 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.accountId=accountId;
this.eventDate=enentDate; this.eventDate=enentDate;
this.note = note;
} }
public Long getAccountId() { public Long getAccountId() {
@@ -20,4 +23,8 @@ public class DepositStateTransitionCommand {
return eventDate; return eventDate;
} }
public String getNote() {
return note;
}
} }
@@ -13,11 +13,6 @@ public class UndoStateTransitionCommand {
this.note = note; this.note = note;
} }
public UndoStateTransitionCommand(final Long loanId) {
this.loanId = loanId;
this.note=null;
}
public Long getLoanId() { public Long getLoanId() {
return this.loanId; return this.loanId;
} }
@@ -1105,15 +1105,16 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType(); Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap); 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); checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>(); Set<String> modifiedParameters = new HashSet<String>();
LocalDate eventDate = extractLocalDateParameter("eventDate", requestMap, modifiedParameters); LocalDate eventDate = extractLocalDateParameter("eventDate", requestMap, modifiedParameters);
String note =extractStringParameter("note", requestMap, modifiedParameters);
return new DepositStateTransitionCommand(resourceIdentifier, eventDate); return new DepositStateTransitionCommand(resourceIdentifier, eventDate, note);
} }
@Override @Override
@@ -1127,7 +1128,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType(); Type typeOfMap = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap); 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); checkForUnsupportedParameters(requestMap, supportedParams);
@@ -1139,7 +1140,8 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Integer interestCompoundedEveryPeriodType = extractIntegerParameter("interestCompoundedEveryPeriodType", requestMap, modifiedParameters); Integer interestCompoundedEveryPeriodType = extractIntegerParameter("interestCompoundedEveryPeriodType", requestMap, modifiedParameters);
Integer interestCompoundedEvery = extractIntegerParameter("interestCompoundedEvery", requestMap, modifiedParameters); Integer interestCompoundedEvery = extractIntegerParameter("interestCompoundedEvery", requestMap, modifiedParameters);
Long productId = extractLongParameter("productId", 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.infrastructure.AbstractAuditableCustom;
import org.mifosng.platform.loan.domain.Loan; import org.mifosng.platform.loan.domain.Loan;
import org.mifosng.platform.loan.domain.LoanTransaction; import org.mifosng.platform.loan.domain.LoanTransaction;
import org.mifosng.platform.saving.domain.DepositAccount;
import org.mifosng.platform.user.domain.AppUser; import org.mifosng.platform.user.domain.AppUser;
@Entity @Entity
@@ -37,8 +38,12 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "note_type_enum") @Column(name = "note_type_enum")
private Integer noteTypeId; private Integer noteTypeId;
@ManyToOne
@JoinColumn(name = "deposit_account_id", nullable = true)
private DepositAccount depositAccount;
public enum NoteType { 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 Integer value;
private String code; private String code;
@@ -104,6 +109,13 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
this.noteTypeId = null; 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) { public void update(final String note) {
this.note = note; this.note = note;
} }
@@ -111,4 +123,8 @@ public class Note extends AbstractAuditableCustom<AppUser, Long> {
public boolean isNotAgainstClientWithIdOf(Long clientId) { public boolean isNotAgainstClientWithIdOf(Long clientId) {
return !this.client.identifiedBy(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: case LOAN_TRANSACTION:
optionData = new EnumOptionData(type.getValue().longValue(), type.getCode(), "Loan transaction note"); optionData = new EnumOptionData(type.getValue().longValue(), type.getCode(), "Loan transaction note");
break; break;
case DEPOSIT:
optionData = new EnumOptionData(type.getValue().longValue(), type.getCode(), "Deposit transaction note");
break;
default:
break;
} }
return optionData; return optionData;
} }
@@ -370,4 +370,8 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
public Money getDeposit() { public Money getDeposit() {
return Money.of(this.currency, this.depositAmount); 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.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosng.platform.api.commands.DepositAccountCommand; import org.mifosng.platform.api.commands.DepositAccountCommand;
import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand; import org.mifosng.platform.api.commands.DepositStateTransitionApprovalCommand;
import org.mifosng.platform.api.commands.DepositStateTransitionCommand; import org.mifosng.platform.api.commands.DepositStateTransitionCommand;
import org.mifosng.platform.api.commands.UndoStateTransitionCommand; import org.mifosng.platform.api.commands.UndoStateTransitionCommand;
import org.mifosng.platform.api.data.EntityIdentifier; 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.DepositAccountNotFoundException;
import org.mifosng.platform.exceptions.NoAuthorizationException; import org.mifosng.platform.exceptions.NoAuthorizationException;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
@@ -37,18 +40,21 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
private final DepositAccountRepository depositAccountRepository; private final DepositAccountRepository depositAccountRepository;
private final DepositAccountAssembler depositAccountAssembler; private final DepositAccountAssembler depositAccountAssembler;
private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator; private final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator;
private final NoteRepository noteRepository;
@Autowired @Autowired
public DepositAccountWritePlatformServiceJpaRepositoryImpl( public DepositAccountWritePlatformServiceJpaRepositoryImpl(
final PlatformSecurityContext context, final PlatformSecurityContext context,
final DepositAccountRepository depositAccountRepository, final DepositAccountRepository depositAccountRepository,
final DepositAccountAssembler depositAccountAssembler, final DepositAccountAssembler depositAccountAssembler,
final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator final FixedTermDepositInterestCalculator fixedTermDepositInterestCalculator,
final NoteRepository noteRepository
) { ) {
this.context=context; this.context=context;
this.depositAccountRepository = depositAccountRepository; this.depositAccountRepository = depositAccountRepository;
this.depositAccountAssembler = depositAccountAssembler; this.depositAccountAssembler = depositAccountAssembler;
this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator; this.fixedTermDepositInterestCalculator = fixedTermDepositInterestCalculator;
this.noteRepository = noteRepository;
} }
/* /*
@@ -126,6 +132,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
this.depositAccountRepository.save(account); 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()); return new EntityIdentifier(account.getId());
@@ -161,6 +173,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
account.reject(eventDate, defaultDepositLifecycleStateMachine()); account.reject(eventDate, defaultDepositLifecycleStateMachine());
this.depositAccountRepository.save(account); 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()); return new EntityIdentifier(account.getId());
} }
@@ -184,6 +202,14 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
} }
account.withdrawnByApplicant(eventDate, defaultDepositLifecycleStateMachine()); 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()); return new EntityIdentifier(account.getId());
} }
@@ -201,6 +227,11 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
account.undoDepositApproval(defaultDepositLifecycleStateMachine()); account.undoDepositApproval(defaultDepositLifecycleStateMachine());
this.depositAccountRepository.save(account); 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()); return new EntityIdentifier(account.getId());
} }
} }
@@ -23,12 +23,14 @@ public class DepositStateTransitionApprovalCommandValidator {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.transition"); DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.transition");
baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); 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("depositAmount").value(command.getDepositAmount()).ignoreIfNull().zeroOrPositiveAmount();
baseDataValidator.reset().parameter("tenureInMonths").value(command.getTenureInMonths()).ignoreIfNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("tenureInMonths").value(command.getTenureInMonths()).ignoreIfNull().integerGreaterThanZero();
baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(command.getInterestCompoundedEveryPeriodType()).ignoreIfNull().inMinMaxRange(2, 2); baseDataValidator.reset().parameter("interestCompoundedEveryPeriodType").value(command.getInterestCompoundedEveryPeriodType()).ignoreIfNull().inMinMaxRange(2, 2);
baseDataValidator.reset().parameter("note").value(command.getNote()).notNull();
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); 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"); DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("deposit.transition");
baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero(); baseDataValidator.reset().parameter("accountId").value(command.getAccountId()).notNull().integerGreaterThanZero();
baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull(); baseDataValidator.reset().parameter("eventDate").value(command.getEventDate()).notNull();
baseDataValidator.reset().parameter("note").value(command.getNote()).notNull();
if (!dataValidationErrors.isEmpty()) { if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);