Search in sources :

Example 26 with CustomerException

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

the class GroupServiceFacadeWebTier method createNewGroup.

@Override
public CustomerDetailsDto createNewGroup(GroupCreationDetail groupCreationDetail, MeetingDto meetingDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
    userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
    GroupBO group;
    try {
        List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(groupCreationDetail.getFeesToApply());
        PersonnelBO formedBy = this.personnelDao.findPersonnelById(groupCreationDetail.getLoanOfficerId());
        Short officeId;
        String groupName = groupCreationDetail.getDisplayName();
        CustomerStatus customerStatus = CustomerStatus.fromInt(groupCreationDetail.getCustomerStatus());
        String externalId = groupCreationDetail.getExternalId();
        boolean trained = groupCreationDetail.isTrained();
        DateTime trainedOn = groupCreationDetail.getTrainedOn();
        DateTime mfiJoiningDate = groupCreationDetail.getMfiJoiningDate();
        DateTime activationDate = groupCreationDetail.getActivationDate();
        AddressDto dto = groupCreationDetail.getAddressDto();
        Address address = null;
        if (dto != null) {
            address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
        }
        MeetingBO groupMeeting = null;
        if (meetingDto != null) {
            groupMeeting = new MeetingFactory().create(meetingDto);
            groupMeeting.setUserContext(userContext);
        }
        if (ClientRules.getCenterHierarchyExists()) {
            CenterBO parentCustomer = this.customerDao.findCenterBySystemId(groupCreationDetail.getParentSystemId());
            //                loanOfficerId = parentCustomer.getPersonnel().getPersonnelId();
            officeId = parentCustomer.getOffice().getOfficeId();
            groupMeeting = parentCustomer.getCustomerMeetingValue();
            group = GroupBO.createGroupWithCenterAsParent(userContext, groupName, formedBy, parentCustomer, address, externalId, trained, trainedOn, customerStatus, mfiJoiningDate, activationDate);
        } else {
            // create group without center as parent
            Short loanOfficerId = groupCreationDetail.getLoanOfficerId() != null ? groupCreationDetail.getLoanOfficerId() : userContext.getId();
            officeId = groupCreationDetail.getOfficeId();
            OfficeBO office = this.officeDao.findOfficeById(groupCreationDetail.getOfficeId());
            PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
            int numberOfCustomersInOfficeAlready = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
            group = GroupBO.createGroupAsTopOfCustomerHierarchy(userContext, groupName, formedBy, groupMeeting, loanOfficer, office, address, externalId, trained, trainedOn, customerStatus, numberOfCustomersInOfficeAlready, mfiJoiningDate, activationDate);
        }
        try {
            personnelDao.checkAccessPermission(userContext, group.getOfficeId(), group.getLoanOfficerId());
        } catch (AccountException e) {
            throw new MifosRuntimeException("Access denied!", e);
        }
        this.customerService.createGroup(group, groupMeeting, feesForCustomerAccount);
        return new CustomerDetailsDto(group.getCustomerId(), group.getGlobalCustNum());
    } catch (CustomerException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CenterBO(org.mifos.customers.center.business.CenterBO) MifosUser(org.mifos.security.MifosUser) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) AddressDto(org.mifos.dto.domain.AddressDto) MeetingFactory(org.mifos.application.meeting.business.MeetingFactory) DateTime(org.joda.time.DateTime) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountException(org.mifos.accounts.exceptions.AccountException) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 27 with CustomerException

use of org.mifos.customers.exceptions.CustomerException 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 28 with CustomerException

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

the class CenterStatusChangeIntegrationTest method givenCenterIsInactiveAndAssignedLoanOfficerIsInactiveShouldNotPassValidationWhenTryingToTranistionClientToActive.

@Test
public void givenCenterIsInactiveAndAssignedLoanOfficerIsInactiveShouldNotPassValidationWhenTryingToTranistionClientToActive() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().with(existingMeeting).withName("Center-IntegrationTest").with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    existingCenter.updateCustomerStatus(CustomerStatus.CENTER_INACTIVE);
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    existingLoanOfficer = this.personnelDao.findPersonnelById(existingLoanOfficer.getPersonnelId());
    updatePersonnel(existingLoanOfficer, PersonnelLevel.LOAN_OFFICER, PersonnelStatus.INACTIVE, existingOffice);
    GroupBO existingPartialGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_PARTIAL).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingPartialGroup, existingMeeting);
    ClientBO existingPartialClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_PARTIAL).withParentCustomer(existingPartialGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingPartialClient, existingMeeting);
    StaticHibernateUtil.flushAndClearSession();
    existingCenter = this.customerDao.findCenterBySystemId(existingCenter.getGlobalCustNum());
    existingCenter.setUserContext(TestUtils.makeUser());
    existingPartialGroup = this.customerDao.findGroupBySystemId(existingPartialGroup.getGlobalCustNum());
    existingPartialClient = this.customerDao.findClientBySystemId(existingPartialClient.getGlobalCustNum());
    existingPartialClient.setUserContext(TestUtils.makeUser());
    CustomerStatusFlag customerStatusFlag = null;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("go active", new Date(), existingCenter.getPersonnel(), existingCenter);
    // exercise test
    try {
        customerService.updateCenterStatus(existingCenter, CustomerStatus.CENTER_ACTIVE, customerStatusFlag, customerNote);
        fail("should fail validation");
    } catch (CustomerException expected) {
        assertThat(expected.getKey(), is(CustomerConstants.CUSTOMER_LOAN_OFFICER_INACTIVE_EXCEPTION));
        assertThat(existingCenter.getStatus(), is(CustomerStatus.CENTER_INACTIVE));
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) Date(java.util.Date) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 29 with CustomerException

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

the class CenterStatusChangeIntegrationTest method shouldValidateStatusWithActiveGroups.

@Test
public void shouldValidateStatusWithActiveGroups() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().withName("Center-IntegrationTest").with(existingMeeting).with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    GroupBO existingActiveGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_ACTIVE).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingActiveGroup, existingMeeting);
    ClientBO existingCancelledClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_CANCELLED).withParentCustomer(existingActiveGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingCancelledClient, existingMeeting);
    existingCenter = this.customerDao.findCenterBySystemId(existingCenter.getGlobalCustNum());
    existingCenter.setUserContext(TestUtils.makeUserWithLocales());
    existingActiveGroup = this.customerDao.findGroupBySystemId(existingActiveGroup.getGlobalCustNum());
    existingCancelledClient = this.customerDao.findClientBySystemId(existingCancelledClient.getGlobalCustNum());
    CustomerStatusFlag customerStatusFlag = null;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("go inactive", new Date(), existingCenter.getPersonnel(), existingCenter);
    // exercise test
    try {
        customerService.updateCenterStatus(existingCenter, CustomerStatus.CENTER_INACTIVE, customerStatusFlag, customerNote);
        fail("should fail validation");
    } catch (CustomerException expected) {
        // verification
        assertThat(expected.getKey(), is(CustomerConstants.ERROR_STATE_CHANGE_EXCEPTION));
        assertThat(existingCenter.getStatus(), is(CustomerStatus.CENTER_ACTIVE));
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) GroupBO(org.mifos.customers.group.business.GroupBO) Date(java.util.Date) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Test(org.junit.Test)

Example 30 with CustomerException

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

the class ClientStatusChangeIntegrationTest method givenClientHasActiveAccountsShouldNotPassValidationWhenTryingToTranistionClientToClosed.

@Test
public void givenClientHasActiveAccountsShouldNotPassValidationWhenTryingToTranistionClientToClosed() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().with(existingMeeting).withName("Center-IntegrationTest").with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    GroupBO existingActiveGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_ACTIVE).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingActiveGroup, existingMeeting);
    ClientBO existingActiveClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_ACTIVE).withParentCustomer(existingActiveGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingActiveClient, existingMeeting);
    StaticHibernateUtil.flushAndClearSession();
    DateTime startDate = new DateTime().minusDays(14);
    LoanOfferingBO clientLoanProduct = new LoanProductBuilder().appliesToClientsOnly().withGlobalProductNumber("XXX-00002").active().withMeeting(existingMeeting).withName("Loan-client").withShortName("dsvd").withStartDate(startDate).withDefaultInterest(1.2).buildForIntegrationTests();
    IntegrationTestObjectMother.createProduct(clientLoanProduct);
    LoanBO clientLoan = new LoanAccountBuilder().withLoanProduct(clientLoanProduct).withCustomer(existingActiveClient).withOriginalLoanAmount(600.0).build();
    IntegrationTestObjectMother.saveLoanAccount(clientLoan);
    existingActiveGroup = this.customerDao.findGroupBySystemId(existingActiveGroup.getGlobalCustNum());
    existingActiveClient = this.customerDao.findClientBySystemId(existingActiveClient.getGlobalCustNum());
    existingActiveClient.setUserContext(TestUtils.makeUser());
    CustomerStatusFlag customerStatusFlag = null;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("go active", new Date(), existingActiveClient.getPersonnel(), existingActiveClient);
    // exercise test
    try {
        customerService.updateClientStatus(existingActiveClient, existingActiveClient.getStatus(), CustomerStatus.CLIENT_CLOSED, customerStatusFlag, customerNote);
        fail("should fail validation");
    } catch (CustomerException expected) {
        assertThat(expected.getKey(), is(CustomerConstants.CUSTOMER_HAS_ACTIVE_ACCOUNTS_EXCEPTION));
        assertThat(existingActiveClient.getStatus(), is(CustomerStatus.CLIENT_ACTIVE));
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerStatusFlag(org.mifos.customers.util.helpers.CustomerStatusFlag) LoanAccountBuilder(org.mifos.domain.builders.LoanAccountBuilder) GroupBuilder(org.mifos.domain.builders.GroupBuilder) ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanProductBuilder(org.mifos.domain.builders.LoanProductBuilder) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) DateTime(org.joda.time.DateTime) Date(java.util.Date) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) GroupBO(org.mifos.customers.group.business.GroupBO) ClientBuilder(org.mifos.domain.builders.ClientBuilder) 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