Search in sources :

Example 1 with GroupUpdate

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

the class GroupCustAction method update.

@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    GroupBO group = (GroupBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    GroupCustActionForm actionForm = (GroupCustActionForm) form;
    boolean trained = false;
    if (actionForm.getTrainedValue() != null && actionForm.getTrainedValue().equals(Short.valueOf("1"))) {
        trained = true;
    }
    AddressDto address = null;
    if (actionForm.getAddress() != null) {
        address = Address.toDto(actionForm.getAddress());
    }
    GroupUpdate groupUpdate = new GroupUpdate(group.getCustomerId(), group.getGlobalCustNum(), group.getVersionNo(), actionForm.getDisplayName(), actionForm.getLoanOfficerIdValue(), actionForm.getExternalId(), trained, actionForm.getTrainedDate(), address, actionForm.getCustomFields(), actionForm.getCustomerPositions());
    try {
        this.groupServiceFacade.updateGroup(groupUpdate);
    } catch (BusinessRuleException e) {
        throw new ApplicationException(e.getMessageKey(), e);
    }
    return mapping.findForward(ActionForwards.update_success.toString());
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) GroupBO(org.mifos.customers.group.business.GroupBO) AddressDto(org.mifos.dto.domain.AddressDto) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) GroupUpdate(org.mifos.dto.domain.GroupUpdate) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with GroupUpdate

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

the class GroupUpdateTest method updatesLoanOfficerForAllChildrenAndThierAccountsWhenLoanOfficerIsUpdated.

@Test
public void updatesLoanOfficerForAllChildrenAndThierAccountsWhenLoanOfficerIsUpdated() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
    when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
    when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(true);
    when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(mockedGroup).setLoanOfficer(newLoanOfficer);
    verify(mockedGroup).validate();
    verify(customerDao).updateLoanOfficersForAllChildrenAndAccounts(anyShort(), anyString(), anyShort());
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Example 3 with GroupUpdate

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

the class GroupUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.

@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
    when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
    when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(false);
    when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
    // stub
    doThrow(new RuntimeException()).when(customerDao).save(mockedGroup);
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(hibernateTransactionHelper).rollbackTransaction();
    verify(hibernateTransactionHelper).closeSession();
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Example 4 with GroupUpdate

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

the class GroupUpdateTest method rollsbackTransactionClosesSessionAndReThrowsApplicationException.

@Test(expected = CustomerException.class)
public void rollsbackTransactionClosesSessionAndReThrowsApplicationException() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    PersonnelBO newLoanOfficer = new PersonnelBuilder().anyLoanOfficer();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    when(mockedGroup.isNameDifferent(groupUpdate.getDisplayName())).thenReturn(false);
    when(personnelDao.findPersonnelById(groupUpdate.getLoanOfficerId())).thenReturn(newLoanOfficer);
    when(mockedGroup.isLoanOfficerChanged(newLoanOfficer)).thenReturn(false);
    when(mockedGroup.getOffice()).thenReturn(new OfficeBuilder().build());
    // stub
    doThrow(new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER)).when(mockedGroup).validate();
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(hibernateTransactionHelper).rollbackTransaction();
    verify(hibernateTransactionHelper).closeSession();
}
Also used : PersonnelBuilder(org.mifos.domain.builders.PersonnelBuilder) OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) CustomerException(org.mifos.customers.exceptions.CustomerException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Example 5 with GroupUpdate

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

the class GroupUpdateTest method trainedDetailsAreUpdated.

@Test
public void trainedDetailsAreUpdated() throws Exception {
    // setup
    UserContext userContext = TestUtils.makeUser();
    GroupUpdate groupUpdate = new GroupUpdateBuilder().build();
    // stubbing
    when(customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum())).thenReturn(mockedGroup);
    // exercise test
    customerService.updateGroup(userContext, groupUpdate);
    // verification
    verify(mockedGroup).updateTrainedDetails(groupUpdate);
}
Also used : GroupUpdateBuilder(org.mifos.domain.builders.GroupUpdateBuilder) UserContext(org.mifos.security.util.UserContext) GroupUpdate(org.mifos.dto.domain.GroupUpdate) Test(org.junit.Test)

Aggregations

GroupUpdate (org.mifos.dto.domain.GroupUpdate)9 Test (org.junit.Test)8 GroupUpdateBuilder (org.mifos.domain.builders.GroupUpdateBuilder)8 UserContext (org.mifos.security.util.UserContext)8 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)4 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)3 PersonnelBuilder (org.mifos.domain.builders.PersonnelBuilder)3 CustomerException (org.mifos.customers.exceptions.CustomerException)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 GroupBO (org.mifos.customers.group.business.GroupBO)1 GroupCustActionForm (org.mifos.customers.group.struts.actionforms.GroupCustActionForm)1 AddressDto (org.mifos.dto.domain.AddressDto)1 ApplicationException (org.mifos.framework.exceptions.ApplicationException)1 CloseSession (org.mifos.framework.util.helpers.CloseSession)1 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1 InOrder (org.mockito.InOrder)1