Search in sources :

Example 11 with ClientBO

use of org.mifos.customers.client.business.ClientBO 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 12 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class PictureFormFile method editMfiInfo.

@TransactionDemarcate(joinToken = true)
public ActionForward editMfiInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    actionForm.clearMostButNotAllFieldsOnActionForm();
    ClientBO clientFromSession = getClientFromSession(request);
    String clientSystemId = clientFromSession.getGlobalCustNum();
    ClientMfiInfoDto mfiInfoDto = this.clientServiceFacade.retrieveMfiInfoForEdit(clientSystemId);
    SessionUtils.setAttribute(GroupConstants.CENTER_HIERARCHY_EXIST, ClientRules.getCenterHierarchyExists(), request);
    SessionUtils.setCollectionAttribute(CustomerConstants.LOAN_OFFICER_LIST, mfiInfoDto.getLoanOfficersList(), request);
    actionForm.setGroupDisplayName(mfiInfoDto.getGroupDisplayName());
    actionForm.setCenterDisplayName(mfiInfoDto.getCenterDisplayName());
    actionForm.setLoanOfficerId(mfiInfoDto.getCustomerDetail().getLoanOfficerIdAsString());
    actionForm.setCustomerId(mfiInfoDto.getCustomerDetail().getCustomerId().toString());
    actionForm.setGlobalCustNum(mfiInfoDto.getCustomerDetail().getGlobalCustNum());
    actionForm.setExternalId(mfiInfoDto.getCustomerDetail().getExternalId());
    actionForm.setGroupFlag(mfiInfoDto.getClientDetail().getGroupFlagAsString());
    actionForm.setParentGroupId(mfiInfoDto.getClientDetail().getParentGroupId().toString());
    actionForm.setTrained(mfiInfoDto.getClientDetail().getTrainedAsString());
    actionForm.setTrainedDate(mfiInfoDto.getClientDetail().getTrainedDate());
    actionForm.setDateOfBirth(clientFromSession.getDateOfBirth());
    ClientBO client = this.customerDao.findClientBySystemId(clientSystemId);
    SessionUtils.removeThenSetAttribute(Constants.BUSINESS_KEY, client, request);
    return mapping.findForward(ActionForwards.editMfiInfo_success.toString());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) ClientBO(org.mifos.customers.client.business.ClientBO) ClientMfiInfoDto(org.mifos.dto.screen.ClientMfiInfoDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 13 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class ClientTransferAction method updateParent.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward updateParent(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientTransferActionForm actionForm = (ClientTransferActionForm) form;
    ClientBO clientInSession = (ClientBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    String globalCustNum = this.clientServiceFacade.transferClientToGroup(actionForm.getParentGroupIdValue(), clientInSession.getGlobalCustNum(), clientInSession.getVersionNo());
    ClientBO client = this.customerDao.findClientBySystemId(globalCustNum);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, client, request);
    return mapping.findForward(ActionForwards.update_success.toString());
}
Also used : ClientTransferActionForm(org.mifos.customers.client.struts.actionforms.ClientTransferActionForm) ClientBO(org.mifos.customers.client.business.ClientBO) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 14 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class LoanAccountActionStrutsTest method testShouldPopulateClientDetailsFromLoan.

@Test
public void testShouldPopulateClientDetailsFromLoan() throws Exception {
    ClientBO clientMock1 = createMock(ClientBO.class);
    expect(clientMock1.getCustomerId()).andReturn(1).anyTimes();
    expect(clientMock1.getDisplayName()).andReturn("client 1");
    ClientBO clientMock2 = createMock(ClientBO.class);
    expect(clientMock2.getCustomerId()).andReturn(2).anyTimes();
    expect(clientMock2.getDisplayName()).andReturn("client 2");
    LoanBO loanMock = createMock(LoanBO.class);
    expect(loanMock.getCustomer()).andReturn(clientMock1).anyTimes();
    expect(loanMock.getBusinessActivityId()).andReturn(3);
    expect(loanMock.getLoanAmount()).andReturn(new Money(getCurrency(), "100")).anyTimes();
    LoanAccountDetailsDto clientDetails1 = new LoanAccountDetailsDto();
    clientDetails1.setClientId("1");
    clientDetails1.setClientName("client 1");
    clientDetails1.setBusinessActivity("3");
    clientDetails1.setLoanAmount("100.0");
    LoanAccountDetailsDto clientDetails2 = new LoanAccountDetailsDto();
    clientDetails2.setClientId("2");
    clientDetails2.setClientName("client 2");
    replay(clientMock1, clientMock2, loanMock);
    List<LoanAccountDetailsDto> clientDetails = new LoanAccountAction().populateClientDetailsFromLoan(Arrays.asList(clientMock1, clientMock2), Arrays.asList(loanMock), new ArrayList<ValueListElement>());
    Assert.assertEquals(Arrays.asList(clientDetails1, clientDetails2), clientDetails);
    verify(clientMock1, clientMock2, loanMock);
}
Also used : Money(org.mifos.framework.util.helpers.Money) ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) ValueListElement(org.mifos.dto.domain.ValueListElement) Test(org.junit.Test)

Example 15 with ClientBO

use of org.mifos.customers.client.business.ClientBO in project head by mifos.

the class LoanAccountActionIndividualLoansIntegrationTest method testShouldCallDeleteMethodIfExistingMembersRemoved.

@Test
public void testShouldCallDeleteMethodIfExistingMembersRemoved() throws Exception {
    GlimLoanUpdater glimLoanUpdaterMock = createMock(GlimLoanUpdater.class);
    LoanAccountAction loanAccountAction = new LoanAccountAction(ApplicationContextProvider.getBean(LoanBusinessService.class), new ConfigurationBusinessService(), glimLoanUpdaterMock);
    LoanBO loanMock = createMock(LoanBO.class);
    Locale locale = Locale.ENGLISH;
    expect(loanMock.getAccountId()).andReturn(2).anyTimes();
    ClientBO customerMock = createMock(ClientBO.class);
    expect(loanMock.getCustomer()).andReturn(customerMock).anyTimes();
    expect(customerMock.getGlobalCustNum()).andReturn("3").anyTimes();
    LoanAccountActionForm loanAccountActionForm = new LoanAccountActionForm();
    List<LoanAccountDetailsDto> clientDetails = new ArrayList<LoanAccountDetailsDto>();
    List<LoanBO> loans = new ArrayList<LoanBO>();
    loans.add(loanMock);
    glimLoanUpdaterMock.delete(loanMock);
    expectLastCall().atLeastOnce();
    replay(glimLoanUpdaterMock, loanMock, customerMock);
    loanAccountAction.handleIndividualLoans(loanMock, loanAccountActionForm, true, clientDetails, loans, locale);
    verify(glimLoanUpdaterMock, loanMock, customerMock);
}
Also used : Locale(java.util.Locale) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) LoanBusinessService(org.mifos.accounts.loan.business.service.LoanBusinessService) LoanBO(org.mifos.accounts.loan.business.LoanBO) ClientBO(org.mifos.customers.client.business.ClientBO) ConfigurationBusinessService(org.mifos.config.business.service.ConfigurationBusinessService) ArrayList(java.util.ArrayList) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) Test(org.junit.Test)

Aggregations

ClientBO (org.mifos.customers.client.business.ClientBO)93 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)27 CustomerException (org.mifos.customers.exceptions.CustomerException)25 CustomerBO (org.mifos.customers.business.CustomerBO)23 GroupBO (org.mifos.customers.group.business.GroupBO)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 UserContext (org.mifos.security.util.UserContext)21 MifosRuntimeException (org.mifos.core.MifosRuntimeException)19 CenterBO (org.mifos.customers.center.business.CenterBO)19 BusinessRuleException (org.mifos.service.BusinessRuleException)17 ClientBuilder (org.mifos.domain.builders.ClientBuilder)16 PersistenceException (org.mifos.framework.exceptions.PersistenceException)16 OfficeBO (org.mifos.customers.office.business.OfficeBO)14 GroupBuilder (org.mifos.domain.builders.GroupBuilder)14 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)14 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)14 Date (java.util.Date)13 DateTime (org.joda.time.DateTime)13 AccountException (org.mifos.accounts.exceptions.AccountException)13