Search in sources :

Example 1 with AccountCustomFieldEntity

use of org.mifos.accounts.business.AccountCustomFieldEntity in project head by mifos.

the class SavingsServiceFacadeWebTier method updateSavingsAccountDetails.

@Override
public void updateSavingsAccountDetails(Long savingsId, String recommendedOrMandatoryAmount, List<CustomFieldDto> customFields) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
    savingsAccount.updateDetails(userContext);
    Set<AccountCustomFieldEntity> accountCustomFields = savingsAccount.getAccountCustomFields();
    for (CustomFieldDto view : customFields) {
        boolean fieldPresent = false;
        if (CustomFieldType.DATE.getValue().equals(view.getFieldType()) && org.apache.commons.lang.StringUtils.isNotBlank(view.getFieldValue())) {
            try {
                SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, userContext.getPreferredLocale());
                String userfmt = DateUtils.convertToCurrentDateFormat(format.toPattern());
                view.setFieldValue(DateUtils.convertUserToDbFmt(view.getFieldValue(), userfmt));
            } catch (InvalidDateException e) {
                throw new BusinessRuleException(e.getMessage(), e);
            }
        }
        for (AccountCustomFieldEntity customFieldEntity : accountCustomFields) {
            if (customFieldEntity.getFieldId().equals(view.getFieldId())) {
                fieldPresent = true;
                customFieldEntity.setFieldValue(view.getFieldValue());
            }
        }
        if (!fieldPresent) {
            accountCustomFields.add(new AccountCustomFieldEntity(savingsAccount, view.getFieldId(), view.getFieldValue()));
        }
    }
    Money amount = new Money(savingsAccount.getCurrency(), recommendedOrMandatoryAmount);
    try {
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        savingsAccount.update(amount, accountCustomFields);
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (Exception e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) SimpleDateFormat(java.text.SimpleDateFormat) AccountCustomFieldEntity(org.mifos.accounts.business.AccountCustomFieldEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 2 with AccountCustomFieldEntity

use of org.mifos.accounts.business.AccountCustomFieldEntity in project head by mifos.

the class SavingsBOIntegrationTest method verifyFields.

private void verifyFields() throws Exception {
    Assert.assertTrue(true);
    Assert.assertEquals(savings.getInterestRate(), savingsOffering.getInterestRate());
    Assert.assertEquals(savings.getMinAmntForInt(), savingsOffering.getMinAmntForInt());
    Assert.assertEquals(savings.getMinAmntForInt(), savingsOffering.getMinAmntForInt());
    Assert.assertEquals(savings.getInterestCalculationMeeting().getMeetingDetails().getRecurAfter(), savingsOffering.getTimePerForInstcalc().getMeeting().getMeetingDetails().getRecurAfter());
    Assert.assertEquals(1, savings.getAccountCustomFields().size());
    Iterator<AccountCustomFieldEntity> itr = savings.getAccountCustomFields().iterator();
    AccountCustomFieldEntity customFieldEntity = itr.next();
    Assert.assertEquals(Short.valueOf("8"), customFieldEntity.getFieldId());
    Assert.assertEquals("13", customFieldEntity.getFieldValue());
    Assert.assertEquals(AccountTypes.SAVINGS_ACCOUNT, savings.getType());
    Assert.assertEquals(group.getPersonnel().getPersonnelId(), savings.getPersonnel().getPersonnelId());
}
Also used : AccountCustomFieldEntity(org.mifos.accounts.business.AccountCustomFieldEntity)

Aggregations

AccountCustomFieldEntity (org.mifos.accounts.business.AccountCustomFieldEntity)2 SimpleDateFormat (java.text.SimpleDateFormat)1 AccountException (org.mifos.accounts.exceptions.AccountException)1 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)1 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)1 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)1 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1 ServiceException (org.mifos.framework.exceptions.ServiceException)1 StatesInitializationException (org.mifos.framework.exceptions.StatesInitializationException)1 Money (org.mifos.framework.util.helpers.Money)1 MifosUser (org.mifos.security.MifosUser)1 UserContext (org.mifos.security.util.UserContext)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1