Search in sources :

Example 71 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class GroupCustAction method search.

@Override
@TransactionDemarcate(joinToken = true)
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    GroupCustActionForm actionForm = (GroupCustActionForm) form;
    UserContext userContext = getUserContext(request);
    ActionForward actionForward = super.search(mapping, form, request, response);
    String searchString = actionForm.getSearchString();
    if (searchString == null) {
        if (actionForm.getInput() != null && actionForm.getInput().equals(GroupConstants.GROUP_SEARCH_CLIENT_TRANSFER)) {
            request.setAttribute(Constants.INPUT, CenterConstants.INPUT_SEARCH_TRANSFERGROUP);
        } else {
            request.setAttribute(Constants.INPUT, null);
        }
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    addSeachValues(searchString, userContext.getBranchId().toString(), new OfficeBusinessService().getOffice(userContext.getBranchId()).getOfficeName(), request);
    final String normalizedSearchString = SearchUtils.normalizeSearchString(searchString);
    if (normalizedSearchString.equals("")) {
        if (actionForm.getInput() != null && actionForm.getInput().equals(GroupConstants.GROUP_SEARCH_CLIENT_TRANSFER)) {
            request.setAttribute(Constants.INPUT, CenterConstants.INPUT_SEARCH_TRANSFERGROUP);
        } else {
            request.setAttribute(Constants.INPUT, null);
        }
        throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
    }
    boolean searchForAddingClientsToGroup = (actionForm.getInput() != null && actionForm.getInput().equals(GroupConstants.GROUP_SEARCH_ADD_CLIENTS_TO_GROUPS));
    GroupSearchResultsDto searchResult = this.customerServiceFacade.searchGroups(searchForAddingClientsToGroup, normalizedSearchString, userContext.getId());
    SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, searchResult.getSearchResults(), request);
    if (actionForm.getInput() != null && actionForm.getInput().equals(GroupConstants.GROUP_SEARCH_CLIENT_TRANSFER)) {
        return mapping.findForward(ActionForwards.transferSearch_success.toString());
    } else if (searchForAddingClientsToGroup) {
        SessionUtils.setQueryResultAttribute(Constants.SEARCH_RESULTS, searchResult.getSearchForAddingClientToGroupResults(), request);
        return mapping.findForward(ActionForwards.addGroupSearch_success.toString());
    } else {
        return actionForward;
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) OfficeBusinessService(org.mifos.customers.office.business.service.OfficeBusinessService) UserContext(org.mifos.security.util.UserContext) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) ActionForward(org.apache.struts.action.ActionForward) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 72 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class CenterCreationTest method throwsCheckedExceptionWhenCenterMeetingAndFeesFailValidation.

@Test(expected = BusinessRuleException.class)
public void throwsCheckedExceptionWhenCenterMeetingAndFeesFailValidation() throws Exception {
    // setup
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    // stubbing
    doThrow(new CustomerException(CustomerConstants.ERRORS_SPECIFY_MEETING)).when(mockedCenter).validateMeetingAndFees(accountFees);
    // exercise test
    customerService.createCenter(mockedCenter, meeting, accountFees);
    // verification
    verify(mockedCenter).validateMeetingAndFees(accountFees);
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 73 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class CenterCreationTest method throwsCheckedExceptionWhenCenterValidationFails.

@Test(expected = BusinessRuleException.class)
public void throwsCheckedExceptionWhenCenterValidationFails() throws Exception {
    // setup
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    // stubbing
    doThrow(new CustomerException(CustomerConstants.ERRORS_SPECIFY_NAME)).when(mockedCenter).validate();
    // exercise test
    customerService.createCenter(mockedCenter, meeting, accountFees);
    // verification
    verify(mockedCenter).validate();
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) ArrayList(java.util.ArrayList) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) Test(org.junit.Test)

Example 74 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class CenterUpdateTest method throwsCheckedExceptionWhenVersionOfCenterForUpdateIsDifferentToPersistedCenterVersion.

@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenVersionOfCenterForUpdateIsDifferentToPersistedCenterVersion() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    CenterUpdate centerUpdate = new CenterUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(centerUpdate.getCustomerId())).thenReturn(mockedCenter);
    doThrow(new CustomerException(Constants.ERROR_VERSION_MISMATCH)).when(mockedCenter).validateVersion(centerUpdate.getVersionNum());
    // exercise test
    customerService.updateCenter(userContext, centerUpdate);
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) CenterUpdateBuilder(org.mifos.domain.builders.CenterUpdateBuilder) CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) Test(org.junit.Test)

Example 75 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class ClientIntegrationTest method testFailureCreateActiveClientWithoutMeeting.

@Test
public void testFailureCreateActiveClientWithoutMeeting() throws Exception {
    try {
        ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.CLIENT.getValue(), TestObjectFactory.SAMPLE_SALUTATION, "first", "", "last", "");
        clientNameDetailDto.setNames(ClientRules.getNameSequence());
        ClientNameDetailDto spouseNameDetailView = new ClientNameDetailDto(NameType.SPOUSE.getValue(), TestObjectFactory.SAMPLE_SALUTATION, "first", "middle", "last", "secondLast");
        spouseNameDetailView.setNames(ClientRules.getNameSequence());
        ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(1, 1, 1, 1, 1, 1, Short.valueOf("1"), Short.valueOf("1"), Short.valueOf("41"));
        client = new ClientBO(TestUtils.makeUser(), clientNameDetailDto.getDisplayName(), CustomerStatus.fromInt(new Short("3")), null, null, null, null, null, null, personnel, officeBo, null, personnel, null, null, null, null, YesNoFlag.NO.getValue(), clientNameDetailDto, spouseNameDetailView, clientPersonalDetailDto, null);
        Assert.fail();
    } catch (CustomerException ce) {
        Assert.assertNull(client);
        Assert.assertEquals(CustomerConstants.INVALID_MEETING, ce.getKey());
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) Test(org.junit.Test)

Aggregations

CustomerException (org.mifos.customers.exceptions.CustomerException)103 Test (org.junit.Test)52 UserContext (org.mifos.security.util.UserContext)29 ClientBO (org.mifos.customers.client.business.ClientBO)23 GroupBuilder (org.mifos.domain.builders.GroupBuilder)21 PersistenceException (org.mifos.framework.exceptions.PersistenceException)21 BusinessRuleException (org.mifos.service.BusinessRuleException)21 CenterBO (org.mifos.customers.center.business.CenterBO)20 GroupBO (org.mifos.customers.group.business.GroupBO)20 AccountException (org.mifos.accounts.exceptions.AccountException)18 CenterBuilder (org.mifos.domain.builders.CenterBuilder)18 ArrayList (java.util.ArrayList)17 MifosRuntimeException (org.mifos.core.MifosRuntimeException)14 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)13 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)13 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)12 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 MifosUser (org.mifos.security.MifosUser)11 DateTime (org.joda.time.DateTime)10