use of org.mifos.dto.domain.ClientPersonalInfoUpdate 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());
}
use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.
the class ClientUpdateTest method clientPersonalDetailsAreUpdated.
@Test
public void clientPersonalDetailsAreUpdated() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
// exercise test
customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
// verification
verify(mockedClient).updatePersonalInfo(clientPersonalInfoUpdate);
}
use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.
the class ClientUpdateTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs2.
@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs2() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
doThrow(new RuntimeException()).when(customerDao).save(mockedClient);
// exercise test
customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
// verification
verify(hibernateTransactionHelper).rollbackTransaction();
verify(hibernateTransactionHelper).closeSession();
}
use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.
the class ClientUpdateTest method throwsCheckedExceptionWhenVersionOfClientForUpdateIsDifferentToPersistedClient.
@Test(expected = CustomerException.class)
public void throwsCheckedExceptionWhenVersionOfClientForUpdateIsDifferentToPersistedClient() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
doThrow(new CustomerException(Constants.ERROR_VERSION_MISMATCH)).when(mockedClient).validateVersion(clientPersonalInfoUpdate.getOriginalClientVersionNumber());
// exercise test
customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
// verify
verify(mockedClient).validateVersion(clientPersonalInfoUpdate.getOriginalClientVersionNumber());
}
use of org.mifos.dto.domain.ClientPersonalInfoUpdate in project head by mifos.
the class ClientUpdateTest method userContextAndUpdateDetailsAreSetBeforeBeginningAuditLoggingForPersonalInfo.
@Test
public void userContextAndUpdateDetailsAreSetBeforeBeginningAuditLoggingForPersonalInfo() throws Exception {
// setup
UserContext userContext = TestUtils.makeUser();
ClientPersonalInfoUpdate clientPersonalInfoUpdate = new ClientPersonalInfoUpdateBuilder().build();
// stubbing
when(customerDao.findCustomerById(clientPersonalInfoUpdate.getCustomerId())).thenReturn(mockedClient);
// exercise test
customerService.updateClientPersonalInfo(userContext, clientPersonalInfoUpdate);
// verification
InOrder inOrder = inOrder(hibernateTransactionHelper, mockedClient);
inOrder.verify(mockedClient).updateDetails(userContext);
inOrder.verify(hibernateTransactionHelper).beginAuditLoggingFor(mockedClient);
}
Aggregations