Search in sources :

Example 1 with ClientPersonalInfoUpdate

use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.

the class PictureFormFile method updatePersonalInfo.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward updatePersonalInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    ClientBO clientInSession = getClientFromSession(request);
    Integer oldClientVersionNumber = clientInSession.getVersionNo();
    Integer customerId = clientInSession.getCustomerId();
    String clientStatus = clientInSession.getCustomerStatus().getName();
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    short loanOfficerId = clientInSession.getCreatedBy();
    final String clientSystemId = clientInSession.getGlobalCustNum();
    ClientPersonalInfoDto clientPersonalInfo = this.clientServiceFacade.retrieveClientPersonalInfoForUpdate(clientSystemId, clientStatus, loanOfficerId);
    AddressDto address = null;
    if (actionForm.getAddress() != null) {
        address = Address.toDto(actionForm.getAddress());
    }
    if (clientPersonalInfo.getCustomerDetail() != null) {
        if (clientPersonalInfo.getCustomerDetail().getAddress() != null) {
            if (clientPersonalInfo.getCustomerDetail().getAddress().getPhoneNumber() != null && (!clientPersonalInfo.getCustomerDetail().getAddress().getPhoneNumber().equals(address.getPhoneNumber()))) {
                UserContext userContext = getUserContext(request);
                if (!ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId())) {
                    throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
                }
            } else if (clientPersonalInfo.getCustomerDetail().getAddress().getPhoneNumber() == null && address.getPhoneNumber() != null && !address.getPhoneNumber().equals("")) {
                UserContext userContext = getUserContext(request);
                if (!ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId())) {
                    throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
                }
            }
        } else if (address.getPhoneNumber() != null && !address.getPhoneNumber().equals("")) {
            UserContext userContext = getUserContext(request);
            if (!ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId())) {
                throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
            }
        }
    } else if (address.getPhoneNumber() != null && !address.getPhoneNumber().equals("")) {
        UserContext userContext = getUserContext(request);
        if (!ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId())) {
            throw new CustomerException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
        }
    }
    ClientNameDetailDto spouseFather = null;
    if (!ClientRules.isFamilyDetailsRequired()) {
        spouseFather = actionForm.getSpouseName();
    }
    InputStream picture = null;
    if (actionForm.getPicture() != null && StringUtils.isNotBlank(actionForm.getPicture().getFileName())) {
        picture = actionForm.getCustomerPicture();
    }
    ClientNameDetailDto clientNameDetails = actionForm.getClientName();
    ClientPersonalDetailDto clientDetail = actionForm.getClientDetailView();
    String governmentId = actionForm.getGovernmentId();
    String clientDisplayName = actionForm.getClientName().getDisplayName();
    String dateOfBirth = actionForm.getDateOfBirth();
    ClientPersonalInfoUpdate personalInfo = new ClientPersonalInfoUpdate(customerId, oldClientVersionNumber, customFields, address, clientDetail, clientNameDetails, spouseFather, picture, governmentId, clientDisplayName, dateOfBirth);
    this.clientServiceFacade.updateClientPersonalInfo(personalInfo, clientStatus, loanOfficerId);
    return mapping.findForward(ActionForwards.updatePersonalInfo_success.toString());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClientBO(org.mifos.customers.client.business.ClientBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientPersonalInfoDto(org.mifos.dto.screen.ClientPersonalInfoDto) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with ClientPersonalInfoUpdate

use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.

the class ClientUpdateTest method clientPersonalDetailsAreUpdated.

@Test
public void clientPersonalDetailsAreUpdated() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verification
    verify(mockedClient).updatePersonalInfo(clientPersonalInfoUpdate);
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Example 3 with ClientPersonalInfoUpdate

use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.

the class ClientUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs2.

@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs2() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    doThrow(new RuntimeException()).when(customerDao).save(mockedClient);
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verification
    verify(hibernateTransactionHelper).rollbackTransaction();
    verify(hibernateTransactionHelper).closeSession();
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) MifosRuntimeException(org.mifos.core.MifosRuntimeException) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Example 4 with ClientPersonalInfoUpdate

use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.

the class ClientUpdateTest method throwsCheckedExceptionWhenVersionOfClientForUpdateIsDifferentToPersistedClient.

@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenVersionOfClientForUpdateIsDifferentToPersistedClient() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    doThrow(new CustomerException(Constants.ERROR_VERSION_MISMATCH)).when(mockedClient).validateVersion(clientPersonalInfoUpdate.getOriginalClientVersionNumber());
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verify
    verify(mockedClient).validateVersion(clientPersonalInfoUpdate.getOriginalClientVersionNumber());
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) CustomerException(org.mifos.customers.exceptions.CustomerException) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Example 5 with ClientPersonalInfoUpdate

use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.

the class ClientUpdateTest method userContextAndUpdateDetailsAreSetBeforeBeginningAuditLoggingForPersonalInfo.

@Test
public void userContextAndUpdateDetailsAreSetBeforeBeginningAuditLoggingForPersonalInfo() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
    // stubbing
    when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
    // exercise test
    customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
    // verification
    InOrder inOrder = inOrder(hibernateTransactionHelper, mockedClient);
    inOrder.verify(mockedClient).updateDetails(userContext);
    inOrder.verify(hibernateTransactionHelper).beginAuditLoggingFor(mockedClient);
}
Also used : ClientPersonalInfoUpdate(org.mifos.dto.domain.ClientPersonalInfoUpdate) InOrder(org.mockito.InOrder) UserContext(org.mifos.security.util.UserContext) ClientPersonalInfoUpdateBuilder(org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder) Test(org.junit.Test)

Aggregations

ClientPersonalInfoUpdate (org.mifos.dto.domain.ClientPersonalInfoUpdate)6 UserContext (org.mifos.security.util.UserContext)6 Test (org.junit.Test)5 ClientPersonalInfoUpdateBuilder (org.mifos.domain.builders.ClientPersonalInfoUpdateBuilder)5 CustomerException (org.mifos.customers.exceptions.CustomerException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 ClientBO (org.mifos.customers.client.business.ClientBO)1 ClientCustActionForm (org.mifos.customers.client.struts.actionforms.ClientCustActionForm)1 AddressDto (org.mifos.dto.domain.AddressDto)1 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)1 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)1 ClientPersonalDetailDto (org.mifos.dto.screen.ClientPersonalDetailDto)1 ClientPersonalInfoDto (org.mifos.dto.screen.ClientPersonalInfoDto)1 CloseSession (org.mifos.framework.util.helpers.CloseSession)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 InOrder (org.mockito.InOrder)1