Search in sources :

Example 71 with ClientBO

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

the class PictureFormFile method retrievePicture.

@TransactionDemarcate(joinToken = true)
public ActionForward retrievePicture(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    ClientBO clientBO = getClientFromSession(request);
    ClientPhotoService cps = ApplicationContextProvider.getBean(ClientPhotoService.class);
    ClientPhoto cp = cps.read(clientBO.getCustomerId().longValue());
    InputStream in = null;
    if (cp != null) {
        in = new ByteArrayInputStream(cps.getData(cp));
        response.setContentType(cp.getImageInfo().getContentType());
    } else {
        in = ClientPhotoService.class.getResourceAsStream("/org/mifos/image/nopicture.png");
        response.setContentType("image/png");
    }
    in.mark(0);
    BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
    // 4K buffer buf, 0, buf.length
    byte[] by = new byte[1024 * 4];
    int index = in.read(by, 0, 1024 * 4);
    while (index != -1) {
        out.write(by, 0, index);
        index = in.read(by, 0, 1024 * 4);
    }
    out.flush();
    out.close();
    in.reset();
    String forward = ClientConstants.CUSTOMER_PICTURE_PAGE;
    return mapping.findForward(forward);
}
Also used : ClientPhoto(org.mifos.framework.image.domain.ClientPhoto) ClientPhotoService(org.mifos.framework.image.service.ClientPhotoService) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClientBO(org.mifos.customers.client.business.ClientBO) BufferedOutputStream(java.io.BufferedOutputStream) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 72 with ClientBO

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

the class PictureFormFile method updateMfiInfo.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward updateMfiInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    ClientBO clientInSession = getClientFromSession(request);
    Integer clientId = clientInSession.getCustomerId();
    Integer oldVersionNumber = clientInSession.getVersionNo();
    boolean trained = false;
    if (trainedValue(actionForm) != null && trainedValue(actionForm).equals(YesNoFlag.YES.getValue())) {
        trained = true;
    }
    DateTime trainedDate = null;
    try {
        java.sql.Date inputDate = trainedDate(actionForm);
        if (inputDate != null) {
            trainedDate = new DateTime(trainedDate(actionForm));
        }
    } catch (InvalidDateException e) {
        throw new CustomerException(ClientConstants.TRAINED_DATE_MANDATORY);
    }
    Short personnelId = Short.valueOf("-1");
    if (groupFlagValue(actionForm).equals(YesNoFlag.NO.getValue())) {
        if (actionForm.getLoanOfficerIdValue() != null) {
            personnelId = actionForm.getLoanOfficerIdValue();
        }
    } else if (groupFlagValue(actionForm).equals(YesNoFlag.YES.getValue())) {
        // TODO for an urgent fix this reads client to get personnelId.
        // Client is read again in updateClientMfiInfo. Refactor to only read in
        // updateClientMfiInfo.
        ClientBO client = (ClientBO) this.customerDao.findCustomerById(clientId);
        personnelId = client.getPersonnel().getPersonnelId();
    }
    ClientMfiInfoUpdate clientMfiInfoUpdate = new ClientMfiInfoUpdate(clientId, oldVersionNumber, personnelId, externalId(actionForm), trained, trainedDate);
    this.clientServiceFacade.updateClientMfiInfo(clientMfiInfoUpdate);
    return mapping.findForward(ActionForwards.updateMfiInfo_success.toString());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) CustomerException(org.mifos.customers.exceptions.CustomerException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ClientMfiInfoUpdate(org.mifos.dto.domain.ClientMfiInfoUpdate) ClientBO(org.mifos.customers.client.business.ClientBO) DateTime(org.joda.time.DateTime) Date(java.sql.Date) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 73 with ClientBO

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

the class GroupTransferAction method removeGroupMemberShip.

@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward removeGroupMemberShip(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    GroupTransferActionForm actionForm = (GroupTransferActionForm) form;
    CustomerBO customerBOInSession = (CustomerBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    ClientBO client = this.customerDao.findClientBySystemId(customerBOInSession.getGlobalCustNum());
    checkVersionMismatch(customerBOInSession.getVersionNo(), client.getVersionNo());
    Short loanOfficerId = null;
    if (StringUtils.isNotBlank(actionForm.getAssignedLoanOfficerId())) {
        loanOfficerId = Short.valueOf(actionForm.getAssignedLoanOfficerId());
    }
    this.clientServiceFacade.removeGroupMembership(customerBOInSession.getGlobalCustNum(), loanOfficerId, actionForm.getComment());
    return mapping.findForward(ActionForwards.view_client_details_page.toString());
}
Also used : GroupTransferActionForm(org.mifos.customers.group.struts.actionforms.GroupTransferActionForm) ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 74 with ClientBO

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

the class GroupTransferAction method loadGrpMemberShip.

@TransactionDemarcate(joinToken = true)
public ActionForward loadGrpMemberShip(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    GroupTransferActionForm actionForm = (GroupTransferActionForm) form;
    actionForm.setComment(null);
    ClientBO clientInSession = (ClientBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    ClientRemovalFromGroupDto clientRemovalFromGroupDetail = this.clientServiceFacade.retreiveClientDetailsForRemovalFromGroup(clientInSession.getGlobalCustNum());
    actionForm.setAssignedLoanOfficerId(clientRemovalFromGroupDetail.getLoanOfficerId().toString());
    actionForm.setIsActive(clientRemovalFromGroupDetail.isActive() ? Constants.YES : Constants.NO);
    ClientBO client = this.customerDao.findClientBySystemId(clientInSession.getGlobalCustNum());
    SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, client, request);
    SessionUtils.setCollectionAttribute(OfficeConstants.OFFICESBRANCHOFFICESLIST, clientRemovalFromGroupDetail.getActiveBranches(), request);
    SessionUtils.setAttribute(CollectionSheetEntryConstants.ISCENTERHIERARCHYEXISTS, clientRemovalFromGroupDetail.isCenterHierarchyExists() ? Constants.YES : Constants.NO, request);
    SessionUtils.setCollectionAttribute(CustomerConstants.LOAN_OFFICER_LIST, clientRemovalFromGroupDetail.getLoanOfficers(), request);
    return mapping.findForward(ActionForwards.loadGrpMemberShip_success.toString());
}
Also used : ClientRemovalFromGroupDto(org.mifos.dto.screen.ClientRemovalFromGroupDto) GroupTransferActionForm(org.mifos.customers.group.struts.actionforms.GroupTransferActionForm) ClientBO(org.mifos.customers.client.business.ClientBO) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 75 with ClientBO

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

the class ClientBuilder method buildForUnitTests.

public ClientBO buildForUnitTests() {
    ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1).shortValue(), Integer.valueOf(1).shortValue(), Integer.valueOf(1).shortValue());
    this.clientDetailEntity = new ClientDetailEntity();
    this.clientDetailEntity.updateClientDetails(clientPersonalDetailDto);
    ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto();
    clientNameDetailDto.setNames("first_name,middle_name,last_name,second_last_name".split(","));
    this.clientNameDetailEntity = new ClientNameDetailEntity(null, null, clientNameDetailDto);
    if (underBranch) {
        ClientBO client = ClientBO.createNewOutOfGroupHierarchy(userContext, name, customerStatus, mfiJoiningDate, office, loanOfficer, meeting, formedBy, clientNameDetailEntity, dateOfBirth, governmentId, trained, trainedDate, groupFlag, clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, externalId, address, 10);
        client.setVersionNo(versionNumber);
        return client;
    }
    if (parentCustomer == null) {
        CenterBO center = new CenterBuilder().withLoanOfficer(loanOfficer).with(meeting).with(office).build();
        parentCustomer = new GroupBuilder().withParentCustomer(center).build();
    }
    ClientBO client = ClientBO.createNewInGroupHierarchy(userContext, name, customerStatus, mfiJoiningDate, parentCustomer, formedBy, clientNameDetailEntity, dateOfBirth, governmentId, trained, trainedDate, groupFlag, clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, associatedOfferings, externalId, address, new LocalDate(activationDate));
    client.setVersionNo(versionNumber);
    return client;
}
Also used : ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientNameDetailEntity(org.mifos.customers.client.business.ClientNameDetailEntity) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) ClientBO(org.mifos.customers.client.business.ClientBO) ClientDetailEntity(org.mifos.customers.client.business.ClientDetailEntity) CenterBO(org.mifos.customers.center.business.CenterBO) LocalDate(org.joda.time.LocalDate)

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