MIFOSX-406: fix application modification and update api docs for application process areas.

This commit is contained in:
Keith Woodlock
2013-07-17 12:45:31 +01:00
parent 5b1b917d04
commit 28f0c80b84
5 changed files with 580 additions and 142 deletions
@@ -27,6 +27,7 @@ public class SavingsApiConstants {
public static String withdrawnByApplicantAction = ".withdrawnByApplicant";
public static String activateAction = ".activate";
public static String modifyApplicationAction = ".modify";
public static String deleteApplicationAction = ".delete";
// general
public static final String localeParamName = "locale";
@@ -85,9 +85,7 @@ public class SavingsAccountDataValidator {
baseDataValidator.reset().parameter(productIdParamName).value(productId).notNull().integerGreaterThanZero();
final LocalDate submittedOnDate = fromApiJsonHelper.extractLocalDateNamed(submittedOnDateParamName, element);
if (submittedOnDate == null) {
baseDataValidator.reset().parameter(submittedOnDateParamName).value(submittedOnDate).notNull();
}
baseDataValidator.reset().parameter(submittedOnDateParamName).value(submittedOnDate).notNull();
if (fromApiJsonHelper.parameterExists(accountNoParamName, element)) {
final String accountNo = fromApiJsonHelper.extractStringNamed(accountNoParamName, element);
@@ -264,6 +262,11 @@ public class SavingsAccountDataValidator {
baseDataValidator.reset().parameter(productIdParamName).value(productId).notNull().integerGreaterThanZero();
}
if (fromApiJsonHelper.parameterExists(submittedOnDateParamName, element)) {
final LocalDate submittedOnDate = fromApiJsonHelper.extractLocalDateNamed(submittedOnDateParamName, element);
baseDataValidator.reset().parameter(submittedOnDateParamName).value(submittedOnDate).notNull();
}
if (fromApiJsonHelper.parameterExists(accountNoParamName, element)) {
final String accountNo = fromApiJsonHelper.extractStringNamed(accountNoParamName, element);
baseDataValidator.reset().parameter(accountNoParamName).value(accountNo).notBlank().notExceedingLengthOf(20);
@@ -98,7 +98,6 @@ public class SavingsAccount extends AbstractPersistable<Long> {
@JoinColumn(name = "product_id", nullable = false)
private SavingsProduct product;
@SuppressWarnings("unused")
@ManyToOne
@JoinColumn(name = "field_officer_id", nullable = true)
private Staff fieldOfficer;
@@ -343,6 +342,14 @@ public class SavingsAccount extends AbstractPersistable<Long> {
return SavingsAccountStatusType.fromInt(this.status).isActive();
}
public boolean isNotSubmittedAndPendingApproval() {
return !isSubmittedAndPendingApproval();
}
public boolean isSubmittedAndPendingApproval() {
return SavingsAccountStatusType.fromInt(this.status).isSubmittedAndPendingApproval();
}
public void postInterest(final SavingsHelper savingsHelper, final MathContext mc, final LocalDate interestPostingUpToDate,
final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds) {
@@ -876,6 +883,11 @@ public class SavingsAccount extends AbstractPersistable<Long> {
actualChanges.put(SavingsApiConstants.productIdParamName, newValue);
}
if (command.isChangeInLongParameterNamed(SavingsApiConstants.fieldOfficerIdParamName, fieldOfficerId())) {
final Long newValue = command.longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName);
actualChanges.put(SavingsApiConstants.fieldOfficerIdParamName, newValue);
}
if (command.isChangeInBigDecimalParameterNamed(SavingsApiConstants.nominalAnnualInterestRateParamName,
this.nominalAnnualInterestRate)) {
final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(SavingsApiConstants.nominalAnnualInterestRateParamName);
@@ -884,6 +896,34 @@ public class SavingsAccount extends AbstractPersistable<Long> {
this.nominalAnnualInterestRate = newValue;
}
if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCompoundingPeriodTypeParamName,
this.interestCompoundingPeriodType)) {
final Integer newValue = command.integerValueOfParameterNamed(SavingsApiConstants.interestCompoundingPeriodTypeParamName);
this.interestCompoundingPeriodType = newValue != null ? SavingsCompoundingInterestPeriodType.fromInt(newValue).getValue()
: newValue;
actualChanges.put(SavingsApiConstants.interestCompoundingPeriodTypeParamName, this.interestCompoundingPeriodType);
}
if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestPostingPeriodTypeParamName, this.interestPostingPeriodType)) {
final Integer newValue = command.integerValueOfParameterNamed(SavingsApiConstants.interestPostingPeriodTypeParamName);
this.interestPostingPeriodType = newValue != null ? SavingsPostingInterestPeriodType.fromInt(newValue).getValue() : newValue;
actualChanges.put(SavingsApiConstants.interestPostingPeriodTypeParamName, this.interestPostingPeriodType);
}
if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCalculationTypeParamName, this.interestCalculationType)) {
final Integer newValue = command.integerValueOfParameterNamed(SavingsApiConstants.interestCalculationTypeParamName);
this.interestCalculationType = newValue != null ? SavingsInterestCalculationType.fromInt(newValue).getValue() : newValue;
actualChanges.put(SavingsApiConstants.interestCalculationTypeParamName, this.interestCalculationType);
}
if (command.isChangeInIntegerParameterNamed(SavingsApiConstants.interestCalculationDaysInYearTypeParamName,
this.interestCalculationDaysInYearType)) {
final Integer newValue = command.integerValueOfParameterNamed(SavingsApiConstants.interestCalculationDaysInYearTypeParamName);
this.interestCalculationDaysInYearType = newValue != null ? SavingsInterestCalculationDaysInYearType.fromInt(newValue)
.getValue() : newValue;
actualChanges.put(SavingsApiConstants.interestCalculationDaysInYearTypeParamName, this.interestCalculationDaysInYearType);
}
if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(SavingsApiConstants.minRequiredOpeningBalanceParamName,
this.minRequiredOpeningBalance)) {
final BigDecimal newValue = command
@@ -1098,6 +1138,10 @@ public class SavingsAccount extends AbstractPersistable<Long> {
this.product = product;
}
public void update(final Staff fieldOfficer) {
this.fieldOfficer = fieldOfficer;
}
public void updateAccountNo(final String newAccountNo) {
this.accountNumber = newAccountNo;
this.accountNumberRequiresAutoGeneration = false;
@@ -1145,6 +1189,14 @@ public class SavingsAccount extends AbstractPersistable<Long> {
return id;
}
public Long fieldOfficerId() {
Long id = null;
if (this.fieldOfficer != null) {
id = this.fieldOfficer.getId();
}
return id;
}
public MonetaryCurrency getCurrency() {
return this.currency;
}
@@ -5,6 +5,8 @@
*/
package org.mifosplatform.portfolio.savings.service;
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -13,14 +15,19 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.accounting.journalentry.service.JournalEntryWritePlatformService;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.core.service.DateUtils;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency;
import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper;
import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency;
import org.mifosplatform.organisation.staff.domain.Staff;
import org.mifosplatform.organisation.staff.domain.StaffRepositoryWrapper;
import org.mifosplatform.portfolio.client.domain.AccountNumberGenerator;
import org.mifosplatform.portfolio.client.domain.AccountNumberGeneratorFactory;
import org.mifosplatform.portfolio.client.domain.Client;
@@ -60,6 +67,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
private final GroupRepository groupRepository;
private final SavingsProductRepository savingsProductRepository;
private final NoteRepository noteRepository;
private final StaffRepositoryWrapper staffRepository;
private final SavingsAccountApplicationTransitionApiJsonValidator savingsAccountApplicationTransitionApiJsonValidator;
private final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepositoryWrapper;
private final JournalEntryWritePlatformService journalEntryWritePlatformService;
@@ -70,7 +78,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
final SavingsAccountDataValidator savingsAccountDataValidator,
final AccountNumberGeneratorFactory accountIdentifierGeneratorFactory, final ClientRepositoryWrapper clientRepository,
final GroupRepository groupRepository, final SavingsProductRepository savingsProductRepository,
final NoteRepository noteRepository,
final NoteRepository noteRepository, final StaffRepositoryWrapper staffRepository,
final SavingsAccountApplicationTransitionApiJsonValidator savingsAccountApplicationTransitionApiJsonValidator,
final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepositoryWrapper,
final JournalEntryWritePlatformService journalEntryWritePlatformService) {
@@ -83,6 +91,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
this.groupRepository = groupRepository;
this.savingsProductRepository = savingsProductRepository;
this.noteRepository = noteRepository;
this.staffRepository = staffRepository;
this.savingsAccountApplicationTransitionApiJsonValidator = savingsAccountApplicationTransitionApiJsonValidator;
this.applicationCurrencyRepositoryWrapper = applicationCurrencyRepositoryWrapper;
this.journalEntryWritePlatformService = journalEntryWritePlatformService;
@@ -198,6 +207,13 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
account.update(product);
}
if (changes.containsKey(SavingsApiConstants.fieldOfficerIdParamName)) {
final Long fieldOfficerId = command.longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName);
final Staff fieldOfficer = this.staffRepository.findOneWithNotFoundDetection(fieldOfficerId);
account.update(fieldOfficer);
}
this.savingAccountRepository.saveAndFlush(account);
}
@@ -220,10 +236,19 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
@Override
public CommandProcessingResult deleteApplication(final Long savingsId) {
this.context.authenticatedUser();
final SavingsAccount account = this.savingAccountRepository.findOneWithNotFoundDetection(savingsId);
if (account.isNotSubmittedAndPendingApproval()) {
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
.resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.deleteApplicationAction);
baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName)
.failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state");
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
}
List<Note> relatedNotes = this.noteRepository.findBySavingsAccountId(savingsId);
this.noteRepository.deleteInBatch(relatedNotes);