Search in sources :

Example 16 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class LoginAction method cancel.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward cancel(ActionMapping mapping, ActionForm form, @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    String username = ((LoginActionForm) form).getUserName();
    PersonnelBO personnelBO = this.personnelDao.findPersonnelByUsername(username);
    String actionForward = getCancelForward(personnelBO.getPasswordChanged());
    return mapping.findForward(actionForward);
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoginActionForm(org.mifos.security.login.struts.actionforms.LoginActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 17 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO 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 18 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class WebTierAccountServiceFacadeTest method shouldAdjustBackdatedPaymentMadeOnAccountIfAllowed.

@Test
public void shouldAdjustBackdatedPaymentMadeOnAccountIfAllowed() throws ServiceException, AccountException, PersistenceException {
    String globalAccountNum = "123";
    String adjustmentNote = "note";
    Short personnelId = Short.valueOf("1");
    PersonnelBO personnelBO = mock(PersonnelBO.class);
    PersonnelBO loanOfficer = mock(PersonnelBO.class);
    Date paymentDate = TestUtils.getDate(10, 10, 2010);
    new DateTimeService().setCurrentDateTime(TestUtils.getDateTime(11, 10, 2010));
    Short recordOfficeId = new Short("1");
    Short recordLoanOfficer = new Short("1");
    Integer paymentId = 1;
    AccountPaymentEntity lastPmntToBeAdjusted = mock(AccountPaymentEntity.class);
    when(loanBO.getLastPmntToBeAdjusted()).thenReturn(lastPmntToBeAdjusted);
    when(loanBO.getOfficeId()).thenReturn(recordOfficeId);
    when(loanBO.getPersonnel()).thenReturn(loanOfficer);
    when(loanBO.getUserContext()).thenReturn(userContext);
    when(loanBO.findPaymentById(paymentId)).thenReturn(lastPmntToBeAdjusted);
    when(loanOfficer.getPersonnelId()).thenReturn(recordOfficeId);
    when(lastPmntToBeAdjusted.getPaymentDate()).thenReturn(paymentDate);
    when(lastPmntToBeAdjusted.getPaymentId()).thenReturn(paymentId);
    when(accountBusinessService.findBySystemId(globalAccountNum)).thenReturn(loanBO);
    when(personnelPersistence.findPersonnelById(personnelId)).thenReturn(personnelBO);
    accountServiceFacade.applyAdjustment(globalAccountNum, adjustmentNote, personnelId);
    verify(accountBusinessService, atLeastOnce()).findBySystemId(globalAccountNum);
    verify(personnelPersistence).findPersonnelById(personnelId);
    verify(loanBO).adjustLastPayment(adjustmentNote, personnelBO);
    verify(loanBO, atLeastOnce()).setUserContext(userContext);
    verify(legacyAccountDao).createOrUpdate(loanBO);
    verify(transactionHelper).startTransaction();
    verify(transactionHelper).commitTransaction();
    verify(accountBusinessService).checkPermissionForAdjustmentOnBackDatedPayments(paymentDate, userContext, recordOfficeId, recordLoanOfficer);
    verify(lastPmntToBeAdjusted, times(2)).getPaymentDate();
}
Also used : 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) Test(org.junit.Test)

Example 19 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class ApplyAdjustmentActionStrutsTest method testApplyAdjustment.

@Ignore
@Test
public void testApplyAdjustment() throws Exception {
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel(PersonnelConstants.SYSTEM_USER);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    loan = (LoanBO) getLoanAccount();
    applyPayment(loan, 212);
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    applyPayment(loan, 700);
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING), new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING), personnel, loan);
    AccountTestUtils.addToAccountStatusChangeHistory(loan, historyEntity);
    TestObjectFactory.updateObject(loan);
    StaticHibernateUtil.flushAndClearSession();
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    loan.setUserContext(userContext);
    for (AccountStatusChangeHistoryEntity accountStatus : loan.getAccountStatusChangeHistory()) {
        Assert.assertEquals(loan.getAccountId(), accountStatus.getAccount().getAccountId());
        Assert.assertNotNull(accountStatus.getAccountStatusChangeId());
        Assert.assertEquals(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue(), accountStatus.getNewStatus().getId());
        Assert.assertEquals(personnel.getPersonnelId(), accountStatus.getPersonnel().getPersonnelId());
        Assert.assertEquals(personnel.getDisplayName(), accountStatus.getPersonnel().getDisplayName());
        Assert.assertEquals("-", accountStatus.getOldStatusName());
        Assert.assertNotNull(accountStatus.getNewStatusName());
        Assert.assertNull(accountStatus.getLocale());
        Assert.assertNotNull(accountStatus.getUserPrefferedTransactionDate());
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
    setRequestPathInfo("/applyAdjustment");
    addRequestParameter("method", "applyAdjustment");
    addRequestParameter("adjustmentNote", "Loan adjustment testing");
    addRequestParameter("globalAccountNum", loan.getGlobalAccountNum());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    setUpSecurityContext();
    getRequest().getSession().setAttribute(Constants.USERCONTEXT, TestUtils.makeUser());
    actionPerform();
    loan = (LoanBO) TestObjectFactory.getObject(AccountBO.class, loan.getAccountId());
    verifyForward("applyadj_success");
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with PersonnelBO

use of org.mifos.customers.personnel.business.PersonnelBO in project head by mifos.

the class ApplyPaymentActionStrutsTest method xtestApplyPaymentForLoanWhenReceiptDateisNull.

public void xtestApplyPaymentForLoanWhenReceiptDateisNull() throws Exception {
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    accountBO = createLoanAccount();
    SessionUtils.setAttribute(Constants.ACCOUNT_VERSION, accountBO.getVersionNo(), request);
    SessionUtils.setAttribute(Constants.ACCOUNT_TYPE, AccountTypes.getAccountType(accountBO.getAccountType().getAccountTypeId()).name(), request);
    SessionUtils.setAttribute(Constants.ACCOUNT_ID, accountBO.getAccountId(), request);
    accountBO.setUserContext(TestObjectFactory.getContext());
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    accountBO.changeStatus(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, null, "", loggedInUser);
    AccountApplyPaymentActionForm accountApplyPaymentActionForm = new AccountApplyPaymentActionForm();
    accountApplyPaymentActionForm.setAmount("212");
    request.getSession().setAttribute("applyPaymentActionForm", accountApplyPaymentActionForm);
    setRequestPathInfo("/applyPaymentAction");
    addRequestParameter("input", "loan");
    addRequestParameter("method", "applyPayment");
    addRequestParameter("accountId", accountBO.getAccountId().toString());
    addRequestParameter("receiptId", "101");
    String currentDate = DateUtils.makeDateAsSentFromBrowser();
    addRequestDateParameter("receiptDate", "");
    addRequestDateParameter("transactionDate", currentDate);
    addRequestParameter("paymentTypeId", "1");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    actionPerform();
    verifyForward("loan_detail_page");
    Assert.assertEquals(new Money(getCurrency()), accountBO.getTotalPaymentDue());
    Assert.assertEquals(0, accountBO.getTotalInstallmentsDue().size());
    Assert.assertEquals(AccountStates.LOANACC_ACTIVEINGOODSTANDING, accountBO.getAccountState().getId().shortValue());
}
Also used : Money(org.mifos.framework.util.helpers.Money) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountApplyPaymentActionForm(org.mifos.accounts.struts.actionforms.AccountApplyPaymentActionForm)

Aggregations

PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)239 Test (org.junit.Test)91 UserContext (org.mifos.security.util.UserContext)65 ArrayList (java.util.ArrayList)62 Money (org.mifos.framework.util.helpers.Money)46 MifosRuntimeException (org.mifos.core.MifosRuntimeException)44 OfficeBO (org.mifos.customers.office.business.OfficeBO)44 MifosUser (org.mifos.security.MifosUser)44 PersistenceException (org.mifos.framework.exceptions.PersistenceException)41 Date (java.util.Date)39 LocalDate (org.joda.time.LocalDate)37 AccountException (org.mifos.accounts.exceptions.AccountException)37 DateTime (org.joda.time.DateTime)36 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)34 BusinessRuleException (org.mifos.service.BusinessRuleException)33 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)31 MeetingBO (org.mifos.application.meeting.business.MeetingBO)30 CustomerBO (org.mifos.customers.business.CustomerBO)27 ServiceException (org.mifos.framework.exceptions.ServiceException)27 LoanBO (org.mifos.accounts.loan.business.LoanBO)25