use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.
the class DateUtilsTest method testGetDateFromBrowser.
public void testGetDateFromBrowser() throws Exception {
// test that day and month order is correct
long expectedDate = new DateMidnight(2005, 03, 04).getMillis();
java.sql.Date result = DateUtils.getDateAsSentFromBrowser("04/03/2005");
Assert.assertEquals(expectedDate, result.getTime());
expectedDate = new DateMidnight(2005, 04, 03).getMillis();
result = DateUtils.getDateAsSentFromBrowser("3/4/2005");
Assert.assertEquals(expectedDate, result.getTime());
// test non-lenient day/month parsing (must be in the normal range, i.e.
// 1-12 for months)
String badDate = "3/15/2006";
try {
result = DateUtils.getDateAsSentFromBrowser(badDate);
Assert.fail();
} catch (InvalidDateException e) {
Assert.assertEquals(badDate, e.getDateString());
}
// test acceptance of two-digit years
expectedDate = new DateMidnight(2005, 5, 5).getMillis();
result = DateUtils.getDateAsSentFromBrowser("5/5/05");
Assert.assertEquals(expectedDate, result.getTime());
}
use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.
the class DateUtilsTest method testParseBrowserDateFields.
public void testParseBrowserDateFields() throws Exception {
long expectedDate = new DateMidnight(2005, 03, 04).getMillis();
java.sql.Date result = DateUtils.parseBrowserDateFields("2005", "3", "4");
Assert.assertEquals(expectedDate, result.getTime());
result = DateUtils.parseBrowserDateFields("05", "03", "04");
Assert.assertEquals(expectedDate, result.getTime());
expectedDate = new DateMidnight(2005, 03, 20).getMillis();
result = DateUtils.parseBrowserDateFields("05", "03", "20");
Assert.assertEquals(expectedDate, result.getTime());
try {
DateUtils.parseBrowserDateFields("2005", "20", "1");
Assert.fail("didn't parse month correctly");
} catch (InvalidDateException e) {
Assert.assertEquals(e.getDateString(), "1/20/2005");
}
}
use of org.mifos.application.admin.servicefacade.InvalidDateException in project head by mifos.
the class LoanBO method handleArrears.
public void handleArrears() throws AccountException {
AccountStateEntity stateEntity;
try {
stateEntity = legacyMasterDao.getPersistentObject(AccountStateEntity.class, AccountStates.LOANACC_BADSTANDING);
} catch (PersistenceException e) {
throw new AccountException(e);
}
AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(this.getAccountState(), stateEntity, this.getPersonnel(), this);
this.addAccountStatusChangeHistory(historyEntity);
this.setAccountState(stateEntity);
try {
String systemDate = DateUtils.getCurrentDate();
Date currrentDate = DateUtils.getLocaleDate(systemDate);
this.setUpdatedDate(currrentDate);
} catch (InvalidDateException ide) {
throw new AccountException(ide);
}
try {
getlegacyLoanDao().createOrUpdate(this);
} catch (PersistenceException e) {
throw new AccountException(e);
}
}
use of org.mifos.application.admin.servicefacade.InvalidDateException 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.application.admin.servicefacade.InvalidDateException in project head by mifos.
the class InterOfficeTransferActionForm method mandatoryCheck.
private ActionErrors mandatoryCheck(UserContext userContext) {
Locale locale = userContext.getPreferredLocale();
ResourceBundle resources = ResourceBundle.getBundle(FilePaths.SIMPLE_ACCOUNTING_RESOURCE, locale);
String trxn_Date = resources.getString(SimpleAccountingConstants.TRXNDATE);
String trxn_Type = resources.getString(SimpleAccountingConstants.TRXNTYPE);
String office_Hierarchy = resources.getString(SimpleAccountingConstants.OFFICE_HIERARCHY);
String officeId = resources.getString(SimpleAccountingConstants.OFFICE);
String main_Account = resources.getString(SimpleAccountingConstants.MAIN_ACCOUNT);
String subAccount = resources.getString(SimpleAccountingConstants.ACCOUNT_HEAD);
String Amount = resources.getString(SimpleAccountingConstants.AMOUNT);
String Notes = resources.getString(SimpleAccountingConstants.TRXN_NOTES);
ActionErrors errors = new ActionErrors();
java.sql.Date currentDate = null;
try {
currentDate = DateUtils.getLocaleDate(userContext.getPreferredLocale(), DateUtils.getCurrentDate(userContext.getPreferredLocale()));
} catch (InvalidDateException ide) {
errors.add(SimpleAccountingConstants.INVALIDDATE, new ActionMessage(SimpleAccountingConstants.INVALIDDATE));
}
java.sql.Date trxnDate = null;
if (getTrxnDate() == null || "".equals(getTrxnDate())) {
errors.add(SimpleAccountingConstants.MANDATORYENTER, new ActionMessage(SimpleAccountingConstants.MANDATORYENTER, trxn_Date));
} else if (getTrxnDate() != null && !getTrxnDate().equals("") && !DateUtils.isValidDate(getTrxnDate())) {
errors = trxnDateValidate(errors, locale);
} else if (DateUtils.isValidDate(getTrxnDate())) {
try {
trxnDate = DateUtils.getDateAsSentFromBrowser(getTrxnDate());
} catch (InvalidDateException ide) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.INVALID_TRXN_DATE, trxn_Date));
}
if (trxnDate.compareTo(currentDate) > 0) {
errors.add(SimpleAccountingConstants.INVALID_FUTURE, new ActionMessage(SimpleAccountingConstants.INVALID_FUTURE, trxn_Date));
}
}
if (fromOfficeHierarchy == null || "".equals(fromOfficeHierarchy.trim())) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, office_Hierarchy));
}
if (fromOffice == null || "".equals(fromOffice.trim())) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, officeId));
}
if (toOfficeHierarchy == null || "".equals(toOfficeHierarchy.trim())) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, office_Hierarchy));
}
if (toOffice == null || "".equals(toOffice.trim())) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, officeId));
}
if (debitAccountHead == null || "".equals(debitAccountHead.trim())) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, main_Account));
}
if (creditAccountHead == null || "".equals(creditAccountHead.trim())) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, subAccount));
}
if (amount == null || "".equals(amount.trim())) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Amount));
}
if (StringUtils.isNotBlank(getAmount())) {
DoubleConversionResult conversionResult = validateAmount(getAmount(), Amount, errors);
if (conversionResult.getErrors().size() == 0 && !(conversionResult.getDoubleValue() > 0.0)) {
addError(errors, SimpleAccountingConstants.AMOUNT, SimpleAccountingConstants.ERRORS_MUST_BE_GREATER_THAN_ZERO, Amount);
}
}
if (notes == null || "".equals(notes.trim())) {
errors.add(SimpleAccountingConstants.MANDATORYFIELDS, new ActionMessage(SimpleAccountingConstants.MANDATORYFIELDS, Notes));
}
if (getChequeDate() != null && !getChequeDate().equals("") && !DateUtils.isValidDate(getChequeDate()))
errors = chequeDateValidate(errors, locale);
return errors;
}
Aggregations