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());
}
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());
}
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();
}
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();
}
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);
}
Aggregations