Search in sources :

Example 86 with ClientBO

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

the class ClientStatusChangeIntegrationTest method givenGroupIsInCancelledStateShouldNotPassValidationWhenTryingToTranistionClientToActive.

@Test
public void givenGroupIsInCancelledStateShouldNotPassValidationWhenTryingToTranistionClientToActive() throws Exception {
    // setup
    CenterBO existingCenter = new CenterBuilder().with(existingMeeting).withName("Center-IntegrationTest").with(existingOffice).withLoanOfficer(existingLoanOfficer).withUserContext().build();
    IntegrationTestObjectMother.createCenter(existingCenter, existingMeeting);
    GroupBO existingCancelledGroup = new GroupBuilder().withName("newGroup").withStatus(CustomerStatus.GROUP_CANCELLED).withParentCustomer(existingCenter).formedBy(existingUser).build();
    IntegrationTestObjectMother.createGroup(existingCancelledGroup, existingMeeting);
    ClientBO existingPartialClient = new ClientBuilder().withStatus(CustomerStatus.CLIENT_PARTIAL).withParentCustomer(existingCancelledGroup).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(existingPartialClient, existingMeeting);
    existingCancelledGroup = this.customerDao.findGroupBySystemId(existingCancelledGroup.getGlobalCustNum());
    existingPartialClient = this.customerDao.findClientBySystemId(existingPartialClient.getGlobalCustNum());
    existingPartialClient.setUserContext(TestUtils.makeUser());
    CustomerStatusFlag customerStatusFlag = null;
    CustomerNoteEntity customerNote = new CustomerNoteEntity("go active", new Date(), existingPartialClient.getPersonnel(), existingPartialClient);
    // exercise test
    try {
        customerService.updateClientStatus(existingPartialClient, existingPartialClient.getStatus(), CustomerStatus.CLIENT_ACTIVE, customerStatusFlag, customerNote);
        fail("should fail validation");
    } catch (CustomerException expected) {
        assertThat(expected.getKey(), is(ClientConstants.ERRORS_GROUP_CANCELLED));
        assertThat(existingPartialClient.getStatus(), is(CustomerStatus.CLIENT_PARTIAL));
    }
}
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 87 with ClientBO

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

the class TestObjectFactory method createClient.

public static ClientBO createClient(final String customerName, final CustomerStatus status, final CustomerBO parentCustomer, final Date startDate) {
    ClientBO client;
    Short personnel = PersonnelConstants.SYSTEM_USER;
    try {
        ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.MAYBE_CLIENT.getValue(), SAMPLE_SALUTATION, customerName, "", customerName, "");
        clientNameDetailDto.setNames(ClientRules.getNameSequence());
        ClientNameDetailDto spouseNameDetailView = new ClientNameDetailDto(NameType.SPOUSE.getValue(), SAMPLE_SALUTATION, customerName, "middle", customerName, "secondLast");
        ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(1, 1, 1, 1, 1, 1, Short.valueOf("1"), Short.valueOf("1"), Short.valueOf("41"));
        // groups
        if (null == parentCustomer) {
            client = new // UserContext
            ClientBO(// UserContext
            TestUtils.makeUserWithLocales(), // String
            clientNameDetailDto.getDisplayName(), // CustomerStatus
            status, // String externalId
            null, // Date mfiJoiningDate
            null, // Address
            null, // List<CustomFieldDto> customFields
            null, // List<FeeDto> fees
            getFees(), // List<SavingsOfferingBO> offeringsSelected
            null, // Short
            getPersonnel(personnel), // Short
            new OfficePersistence().getOffice(SAMPLE_BRANCH_OFFICE), // MeetingBO
            null, // Short loanOfficerId
            null, // Date dateOfBirth
            null, // String governmentId
            "", // Short trained
            null, // Date trainedDate
            null, // Short groupFlag
            YesNoFlag.NO.getValue(), // ClientNameDetailDto
            clientNameDetailDto, // ClientNameDetailDto
            spouseNameDetailView, // ClientPersonalDetailDto
            clientPersonalDetailDto, // InputStream picture
            null);
        } else {
            client = new ClientBO(TestUtils.makeUserWithLocales(), clientNameDetailDto.getDisplayName(), status, null, null, null, null, getFees(), null, getPersonnel(personnel), parentCustomer.getOffice(), parentCustomer, null, null, null, null, YesNoFlag.YES.getValue(), clientNameDetailDto, spouseNameDetailView, clientPersonalDetailDto);
        }
        ApplicationContextProvider.getBean(LegacyClientDao.class).saveClient(client);
        StaticHibernateUtil.flushSession();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return client;
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientBO(org.mifos.customers.client.business.ClientBO) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) LegacyClientDao(org.mifos.customers.client.persistence.LegacyClientDao) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerException(org.mifos.customers.exceptions.CustomerException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) OfficeException(org.mifos.customers.office.exceptions.OfficeException)

Example 88 with ClientBO

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

the class TestObjectFactory method createClient.

public static ClientBO createClient(final String customerName, final CustomerStatus status, final CustomerBO parentCustomer, final List<FeeDto> fees, final String governmentId, final Date dateOfBirth, final Address address) {
    ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(132, 1, 1, 1, 1, 1, Short.valueOf("1"), Short.valueOf("1"), Short.valueOf("41"));
    ClientNameDetailDto clientNameDetailDto = clientNameView(NameType.CLIENT, customerName);
    ClientNameDetailDto spouseNameDetailView = clientNameView(NameType.SPOUSE, customerName);
    ClientBO client;
    try {
        client = new ClientBO(TestUtils.makeUserWithLocales(), customerName, status, null, null, address, null, fees, null, getPersonnel(PersonnelConstants.SYSTEM_USER), new OfficePersistence().getOffice(SAMPLE_BRANCH_OFFICE), parentCustomer, dateOfBirth, governmentId, null, null, YesNoFlag.YES.getValue(), clientNameDetailDto, spouseNameDetailView, clientPersonalDetailDto);
        ApplicationContextProvider.getBean(LegacyClientDao.class).saveClient(client);
    } catch (CustomerException e) {
        throw new RuntimeException(e);
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }
    StaticHibernateUtil.flushSession();
    return client;
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) ClientBO(org.mifos.customers.client.business.ClientBO) LegacyClientDao(org.mifos.customers.client.persistence.LegacyClientDao) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence)

Example 89 with ClientBO

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

the class TestObjectFactory method createClient.

public static ClientBO createClient(final String customerName, final MeetingBO meeting, final CustomerStatus status) {
    ClientBO client;
    try {
        PersonnelBO systemUser = getPersonnel(PersonnelConstants.SYSTEM_USER);
        ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.CLIENT.getValue(), SAMPLE_SALUTATION, customerName, "middle", customerName, "secondLast");
        clientNameDetailDto.setNames(ClientRules.getNameSequence());
        ClientNameDetailDto spouseNameDetailView = new ClientNameDetailDto(NameType.SPOUSE.getValue(), SAMPLE_SALUTATION, customerName, "middle", customerName, "secondLast");
        ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(1, 1, 1, 1, 1, 1, Short.valueOf("1"), Short.valueOf("1"), Short.valueOf("41"));
        client = new ClientBO(TestUtils.makeUserWithLocales(), clientNameDetailDto.getDisplayName(), status, null, null, null, null, getFees(), null, systemUser, new OfficePersistence().getOffice(SAMPLE_BRANCH_OFFICE), meeting, systemUser, new DateTimeService().getCurrentJavaDateTime(), null, null, null, YesNoFlag.NO.getValue(), clientNameDetailDto, spouseNameDetailView, clientPersonalDetailDto, null);
        ApplicationContextProvider.getBean(LegacyClientDao.class).saveClient(client);
        StaticHibernateUtil.flushSession();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return client;
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientBO(org.mifos.customers.client.business.ClientBO) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) LegacyClientDao(org.mifos.customers.client.persistence.LegacyClientDao) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) DateTimeService(org.mifos.framework.util.DateTimeService) SystemException(org.mifos.framework.exceptions.SystemException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) ProductDefinitionException(org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) CustomerException(org.mifos.customers.exceptions.CustomerException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) OfficeException(org.mifos.customers.office.exceptions.OfficeException)

Example 90 with ClientBO

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

the class PersonnelRESTController method getCustomersUnderPersonnel.

@RequestMapping(value = "personnel/id-current/clients", method = RequestMethod.GET)
@ResponseBody
public CustomerHierarchyDto getCustomersUnderPersonnel() {
    PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(getCurrentPersonnel().getPersonnelId());
    CustomerHierarchyDto hierarchy = new CustomerHierarchyDto();
    if (ClientRules.getCenterHierarchyExists()) {
        for (CustomerDetailDto center : this.customerDao.findActiveCentersUnderUser(loanOfficer)) {
            CenterDescriptionDto centerDescription = new CenterDescriptionDto();
            centerDescription.setId(center.getCustomerId());
            centerDescription.setDisplayName(center.getDisplayName());
            centerDescription.setGlobalCustNum(center.getGlobalCustNum());
            centerDescription.setSearchId(center.getSearchId());
            hierarchy.getCenters().add(centerDescription);
        }
    }
    allGroups: for (CustomerDetailDto group : this.customerDao.findGroupsUnderUser(loanOfficer)) {
        GroupDescriptionDto groupDescription = new GroupDescriptionDto();
        groupDescription.setId(group.getCustomerId());
        groupDescription.setDisplayName(group.getDisplayName());
        groupDescription.setGlobalCustNum(group.getGlobalCustNum());
        groupDescription.setSearchId(group.getSearchId());
        for (ClientBO client : this.customerDao.findAllExceptClosedAndCancelledClientsUnderParent(group.getSearchId(), loanOfficer.getOffice().getOfficeId())) {
            ClientDescriptionDto clientDescription = new ClientDescriptionDto();
            clientDescription.setId(client.getCustomerId());
            clientDescription.setDisplayName(client.getDisplayName());
            clientDescription.setGlobalCustNum(client.getGlobalCustNum());
            clientDescription.setSearchId(client.getSearchId());
            groupDescription.getClients().add(clientDescription);
        }
        for (CenterDescriptionDto center : hierarchy.getCenters()) {
            if (group.getSearchId().startsWith(center.getSearchId())) {
                center.getGroups().add(groupDescription);
                continue allGroups;
            }
        }
        hierarchy.getGroups().add(groupDescription);
    }
    for (ClientBO client : this.customerDao.findAllExceptClosedAndCancelledClientsWithoutGroupForLoanOfficer(loanOfficer.getPersonnelId(), loanOfficer.getOffice().getOfficeId())) {
        ClientDescriptionDto clientDescription = new ClientDescriptionDto();
        clientDescription.setId(client.getCustomerId());
        clientDescription.setDisplayName(client.getDisplayName());
        clientDescription.setGlobalCustNum(client.getGlobalCustNum());
        clientDescription.setSearchId(client.getSearchId());
        hierarchy.getClients().add(clientDescription);
    }
    return hierarchy;
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CenterDescriptionDto(org.mifos.dto.domain.CenterDescriptionDto) ClientBO(org.mifos.customers.client.business.ClientBO) CustomerHierarchyDto(org.mifos.dto.domain.CustomerHierarchyDto) CustomerDetailDto(org.mifos.dto.domain.CustomerDetailDto) GroupDescriptionDto(org.mifos.dto.domain.GroupDescriptionDto) ClientDescriptionDto(org.mifos.dto.domain.ClientDescriptionDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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