use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class WebTierAccountServiceFacadeTest method shouldNotAdjustBackdatedPaymentMadeOnAccountIfNotAllowed.
@Test
public void shouldNotAdjustBackdatedPaymentMadeOnAccountIfNotAllowed() throws ServiceException, AccountException, PersistenceException {
String globalAccountNum = "123";
String adjustmentNote = "note";
Short personnelId = Short.valueOf("1");
PersonnelBO personnelBO = mock(PersonnelBO.class);
Date paymentDate = TestUtils.getDate(10, 10, 2010);
new DateTimeService().setCurrentDateTime(TestUtils.getDateTime(11, 10, 2010));
AccountPaymentEntity lastPmntToBeAdjusted = mock(AccountPaymentEntity.class);
Short recordOfficeId = new Short("1");
Short recordLoanOfficer = new Short("1");
PersonnelBO loanOfficer = mock(PersonnelBO.class);
when(loanBO.getPersonnel()).thenReturn(loanOfficer);
when(loanBO.getUserContext()).thenReturn(userContext);
when(loanOfficer.getPersonnelId()).thenReturn(recordOfficeId);
when(loanBO.getOfficeId()).thenReturn(recordOfficeId);
when(loanBO.getLastPmntToBeAdjusted()).thenReturn(lastPmntToBeAdjusted);
when(lastPmntToBeAdjusted.getPaymentDate()).thenReturn(paymentDate);
when(accountBusinessService.findBySystemId(globalAccountNum)).thenReturn(loanBO);
when(personnelPersistence.findPersonnelById(personnelId)).thenReturn(personnelBO);
doThrow(new ServiceException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED)).when(accountBusinessService).checkPermissionForAdjustmentOnBackDatedPayments(paymentDate, userContext, recordOfficeId, recordLoanOfficer);
try {
accountServiceFacade.applyAdjustment(globalAccountNum, adjustmentNote, personnelId);
} catch (MifosRuntimeException e) {
assertThat((ServiceException) e.getCause(), CoreMatchers.any(ServiceException.class));
assertThat(((ServiceException) e.getCause()).getKey(), is(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED));
}
verify(accountBusinessService, atLeastOnce()).findBySystemId(globalAccountNum);
verify(lastPmntToBeAdjusted).getPaymentDate();
verify(accountBusinessService).checkPermissionForAdjustmentOnBackDatedPayments(paymentDate, userContext, recordOfficeId, recordLoanOfficer);
verify(personnelPersistence, never()).findPersonnelById(personnelId);
verify(loanBO, never()).adjustLastPayment(anyString(), Matchers.<PersonnelBO>anyObject());
verify(legacyAccountDao, never()).createOrUpdate(loanBO);
verify(loanBO).setUserContext(userContext);
verify(transactionHelper, never()).startTransaction();
verify(transactionHelper, never()).commitTransaction();
verify(transactionHelper).rollbackTransaction();
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class SavingsApplyAdjustmentAction method adjustLastUserAction.
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward adjustLastUserAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
request.setAttribute("method", "adjustLastUserAction");
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
Integer accountId = savings.getAccountId();
Integer versionNum = savings.getVersionNo();
savings = savingsDao.findById(accountId);
// NOTE: initialise so when error occurs when apply adjustment, savings object is correctly initialised for
// use within Tag library in jsp.
new SavingsPersistence().initialize(savings);
checkVersionMismatch(versionNum, savings.getVersionNo());
savings.setUserContext(uc);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
if (savings.getPersonnel() != null) {
getBizService().checkPermissionForAdjustment(AccountTypes.SAVINGS_ACCOUNT, null, uc, savings.getOffice().getOfficeId(), savings.getPersonnel().getPersonnelId());
} else {
getBizService().checkPermissionForAdjustment(AccountTypes.SAVINGS_ACCOUNT, null, uc, savings.getOffice().getOfficeId(), uc.getId());
}
SavingsApplyAdjustmentActionForm actionForm = (SavingsApplyAdjustmentActionForm) form;
if (actionForm.getLastPaymentAmount() == null) {
throw new MifosRuntimeException("Null payment amount is not allowed");
}
// date validation
Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
if (!savings.isTrxnDateValid(actionForm.getTrxnDateLocal().toDateMidnight().toDate(), meetingDate, repaymentIndependentOfMeetingEnabled)) {
throw new AccountException(AccountConstants.ERROR_INVALID_TRXN);
}
Long savingsId = Long.valueOf(accountId.toString());
Double adjustedAmount = Double.valueOf(actionForm.getLastPaymentAmount());
String note = actionForm.getNote();
AccountPaymentEntity adjustedPayment = savings.findPaymentById(actionForm.getPaymentId());
AccountPaymentEntity otherTransferPayment = adjustedPayment.getOtherTransferPayment();
try {
if (otherTransferPayment == null || otherTransferPayment.isSavingsDepositOrWithdrawal()) {
// regular savings payment adjustment or savings-savings transfer adjustment
SavingsAdjustmentDto savingsAdjustment = new SavingsAdjustmentDto(savingsId, adjustedAmount, note, actionForm.getPaymentId(), actionForm.getTrxnDateLocal());
this.savingsServiceFacade.adjustTransaction(savingsAdjustment);
} else {
// adjust repayment from savings account
AccountBO account = adjustedPayment.getOtherTransferPayment().getAccount();
AdjustedPaymentDto adjustedPaymentDto = new AdjustedPaymentDto(actionForm.getLastPaymentAmount(), actionForm.getTrxnDateLocal().toDateMidnight().toDate(), otherTransferPayment.getPaymentType().getId());
this.accountServiceFacade.applyHistoricalAdjustment(account.getGlobalAccountNum(), otherTransferPayment.getPaymentId(), note, uc.getId(), adjustedPaymentDto);
}
} catch (BusinessRuleException e) {
throw new AccountException(e.getMessageKey(), e);
} finally {
doCleanUp(request);
}
return mapping.findForward("account_detail_page");
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class AccountApplyPaymentActionForm method validateModeOfPaymentSecurity.
private void validateModeOfPaymentSecurity(HttpServletRequest request, ActionErrors errors) {
UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
AccountBO account = null;
Short personnelId = userContext.getId();
try {
if (accountId != null) {
account = new AccountBusinessService().getAccount(Integer.valueOf(accountId));
if (account.getPersonnel() != null) {
personnelId = account.getPersonnel().getPersonnelId();
}
}
} catch (NumberFormatException e) {
throw new MifosRuntimeException(e);
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
if (getPaymentTypeId().equals("4") && !ActivityMapper.getInstance().isModeOfPaymentSecurity(userContext, personnelId)) {
errors.add(AccountConstants.LOAN_TRANSFER_PERMISSION, new ActionMessage(AccountConstants.LOAN_TRANSFER_PERMISSION, getLocalizedMessage("accounts.mode_of_payment_permission")));
}
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class TypeParser method parser.
public Files parser(String filename) throws TableTagTypeParserException {
Files file = null;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
// Specify our own schema - this overrides the schemaLocation in the
// xml file
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "type.xsd");
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(null);
Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
Node fileNode = document.getFirstChild();
file = new Files();
file.setFileName(createFileName(fileNode));
} catch (ParserConfigurationException pce) {
throw new TableTagTypeParserException(pce);
} catch (IOException ioe) {
throw new TableTagTypeParserException(ioe);
} catch (SAXParseException saxpe) {
throw new TableTagTypeParserException(saxpe);
} catch (SAXException saxe) {
throw new TableTagTypeParserException(saxe);
} catch (MifosRuntimeException saxe) {
throw new TableTagTypeParserException(saxe);
}
return file;
}
use of org.mifos.core.MifosRuntimeException in project head by mifos.
the class TableTag method getNonLocalizedFileLookupDatabase.
private Properties getNonLocalizedFileLookupDatabase() {
Properties resource = null;
if (null == nonLocalizedFileLookupDatabase) {
ClassPathResource fileLookupDatabase = new ClassPathResource(FilePaths.TABLE_TAG_PATH_DATABASE);
resource = new Properties();
try {
resource.load(fileLookupDatabase.getInputStream());
} catch (IOException e) {
throw new MifosRuntimeException(e);
}
}
return resource;
}
Aggregations