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();
}
}
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());
}
Aggregations