Search in sources :

Example 46 with MifosRuntimeException

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();
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Matchers.anyString(org.mockito.Matchers.anyString) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Test(org.junit.Test)

Example 47 with MifosRuntimeException

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");
}
Also used : SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) UserContext(org.mifos.security.util.UserContext) ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) SavingsAdjustmentDto(org.mifos.dto.domain.SavingsAdjustmentDto) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) AdjustedPaymentDto(org.mifos.dto.domain.AdjustedPaymentDto) SavingsApplyAdjustmentActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsApplyAdjustmentActionForm) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 48 with MifosRuntimeException

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")));
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ServiceException(org.mifos.framework.exceptions.ServiceException) UserContext(org.mifos.security.util.UserContext) ActionMessage(org.apache.struts.action.ActionMessage) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 49 with MifosRuntimeException

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;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) Node(org.w3c.dom.Node) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) TableTagTypeParserException(org.mifos.framework.exceptions.TableTagTypeParserException) SAXException(org.xml.sax.SAXException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 50 with MifosRuntimeException

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;
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

MifosRuntimeException (org.mifos.core.MifosRuntimeException)305 PersistenceException (org.mifos.framework.exceptions.PersistenceException)136 ArrayList (java.util.ArrayList)102 BusinessRuleException (org.mifos.service.BusinessRuleException)95 UserContext (org.mifos.security.util.UserContext)94 MifosUser (org.mifos.security.MifosUser)87 AccountException (org.mifos.accounts.exceptions.AccountException)79 ServiceException (org.mifos.framework.exceptions.ServiceException)69 ApplicationException (org.mifos.framework.exceptions.ApplicationException)48 LoanBO (org.mifos.accounts.loan.business.LoanBO)41 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)39 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)37 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)36 LocalDate (org.joda.time.LocalDate)35 CustomerBO (org.mifos.customers.business.CustomerBO)29 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)28 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)27 CustomerException (org.mifos.customers.exceptions.CustomerException)27 Money (org.mifos.framework.util.helpers.Money)27 AccountBO (org.mifos.accounts.business.AccountBO)25