use of org.mifos.dto.domain.AddressDto in project head by mifos.
the class SystemUserController method translateUserFormBeanToDto.
@SuppressWarnings("PMD")
private CreateOrUpdatePersonnelInformation translateUserFormBeanToDto(final UserFormBean userFormBean) {
Short officeId = userFormBean.getOfficeId().shortValue();
String firstName = userFormBean.getFirstName();
String middleName = userFormBean.getMiddleName();
String secondLastName = userFormBean.getSecondLastName();
String lastName = userFormBean.getLastName();
String governmentIdNumber = userFormBean.getGovernmentId();
DateTime dateOfBirth = userFormBean.getDateOfBirthAsDateTime();
DateTime mfiJoiningDate = userFormBean.getMfiJoiningDateAsDateTime();
DateTime branchJoiningDate = userFormBean.getMfiJoiningDateAsDateTime();
DateTime passwordExpirationDate = userFormBean.getPasswordExpirationDateAsDateTime();
String email = userFormBean.getEmail();
Integer maritalStatus = null;
if (StringUtils.isNotBlank(userFormBean.getSelectedMaritalStatus())) {
maritalStatus = Integer.valueOf(userFormBean.getSelectedMaritalStatus());
}
Integer gender = Integer.valueOf(userFormBean.getSelectedGender());
Integer title = null;
if (StringUtils.isNotBlank(userFormBean.getSelectedUserTitle())) {
title = Integer.valueOf(userFormBean.getSelectedUserTitle());
}
Short personnelLevelId = Short.valueOf(userFormBean.getSelectedUserHierarchy());
List<ListElement> roles = new ArrayList<ListElement>();
String[] selectedRoles = userFormBean.getSelectedRoles();
if (selectedRoles != null) {
for (String role : selectedRoles) {
roles.add(new ListElement(Integer.valueOf(role), userFormBean.getSelectedRolesOptions().get(role)));
}
}
AddressBean bean = userFormBean.getAddress();
AddressDto address = new AddressDto(bean.getAddress1(), bean.getAddress2(), bean.getAddress3(), bean.getCityDistrict(), bean.getState(), bean.getCountry(), bean.getPostalCode(), bean.getTelephoneNumber());
Short preferredLocale = null;
if (StringUtils.isNotBlank(userFormBean.getSelectedPreferredLanguage())) {
preferredLocale = Short.valueOf(userFormBean.getSelectedPreferredLanguage());
}
String password = userFormBean.getPassword();
String username = userFormBean.getUsername();
// FIXME - add status to screen and support translation from bean to DTO
// active
Short personnelStatusId = Short.valueOf("1");
List<CustomFieldDto> customFields = userFormBean.getCustomFields();
CreateOrUpdatePersonnelInformation personnel = new CreateOrUpdatePersonnelInformation(userFormBean.getUserId(), personnelLevelId, officeId, title, preferredLocale, password, username, email, roles, customFields, firstName, middleName, lastName, secondLastName, governmentIdNumber, dateOfBirth, maritalStatus, gender, mfiJoiningDate, branchJoiningDate, address, personnelStatusId, passwordExpirationDate);
return personnel;
}
use of org.mifos.dto.domain.AddressDto in project head by mifos.
the class SystemUserController method createPopulatedUserFormBean.
public UserFormBean createPopulatedUserFormBean(final Long userId, final UserFormBean formBean) {
PersonnelInformationDto personnelInformation = this.personnelServiceFacade.getPersonnelInformationDto(userId, "");
UserFormBean populatedBean = createUserFormBean(personnelInformation.getOfficeId().longValue(), formBean);
populatedBean.setUserId(userId);
populatedBean.setStatusId(personnelInformation.getStatus().getId());
populatedBean.setDisplayName(personnelInformation.getDisplayName());
PersonnelDetailsDto details = personnelInformation.getPersonnelDetails();
populatedBean.setFirstName(details.getFirstName());
populatedBean.setMiddleName(details.getMiddleName());
populatedBean.setSecondLastName(details.getSecondLastName());
populatedBean.setLastName(details.getLastName());
populatedBean.setGovernmentId(details.getGovernmentIdNumber());
populatedBean.setEmail(personnelInformation.getEmailId());
populatedBean.setDateOfBirthDay(details.getDob().getDayOfMonth());
populatedBean.setDateOfBirthMonth(details.getDob().getMonthOfYear());
populatedBean.setDateOfBirthYear(details.getDob().getYearOfEra());
if (details.getDateOfJoiningMFI() != null) {
populatedBean.setDateOfBirthDay(details.getPasswordExpirationDate().getDayOfMonth());
populatedBean.setDateOfBirthMonth(details.getPasswordExpirationDate().getMonthOfYear());
populatedBean.setDateOfBirthYear(details.getPasswordExpirationDate().getYearOfEra());
}
if (details.getDateOfJoiningMFI() != null) {
populatedBean.setMfiJoiningDateDay(details.getDateOfJoiningMFI().getDayOfMonth());
populatedBean.setMfiJoiningDateMonth(details.getDateOfJoiningMFI().getMonthOfYear());
populatedBean.setMfiJoiningDateYear(details.getDateOfJoiningMFI().getYearOfEra());
}
populatedBean.setSelectedGender(details.getGender().toString());
if (details.getMaritalStatus() != null) {
populatedBean.setSelectedMaritalStatus(details.getMaritalStatus().toString());
}
if (personnelInformation.getPreferredLanguageId() != null) {
populatedBean.setSelectedPreferredLanguage(personnelInformation.getPreferredLanguageId().toString());
}
AddressDto address = details.getAddress();
AddressBean bean = populatedBean.getAddress();
bean.setAddress1(address.getLine1());
bean.setAddress2(address.getLine2());
bean.setAddress3(address.getLine3());
bean.setCityDistrict(address.getCity());
bean.setState(address.getState());
bean.setCountry(address.getCountry());
bean.setPostalCode(address.getZip());
bean.setTelephoneNumber(address.getPhoneNumber());
populatedBean.setAddress(bean);
if (personnelInformation.getTitle() != null) {
populatedBean.setSelectedUserTitle(personnelInformation.getTitle().toString());
}
populatedBean.setSelectedUserHierarchy(personnelInformation.getLevelId().toString());
Set<ListElement> roles = personnelInformation.getPersonnelRoles();
String[] selectedRoles = new String[roles.size()];
int roleIndex = 0;
for (ListElement listElement : roles) {
selectedRoles[roleIndex] = listElement.getId().toString();
roleIndex++;
}
populatedBean.setSelectedRoles(selectedRoles);
populatedBean.setUsername(personnelInformation.getUserName());
List<CustomFieldDto> currentBeanFields = new ArrayList<CustomFieldDto>();
List<CustomFieldDto> defaultBeanFields = populatedBean.getCustomFields();
for (CustomFieldDto customFieldDto : defaultBeanFields) {
CustomFieldDto matchingField = findMatchingAndSetFieldValue(customFieldDto, personnelInformation.getCustomFields());
if (matchingField != null) {
currentBeanFields.add(matchingField);
}
}
populatedBean.setRecentNotes(personnelInformation.getRecentPersonnelNotes());
populatedBean.setCustomFields(currentBeanFields);
populatedBean.prepareForPreview();
populatedBean.prepateForReEdit();
return populatedBean;
}
use of org.mifos.dto.domain.AddressDto in project head by mifos.
the class CenterHierarchyCustomerServiceIntegrationTest method updatingCenterWithDifferentLoanOfficerUpdatesAllChildrenInHierarchyIncludingTheirAssociatedLoansSavingsAndCustomerAccounts.
@Test
public void updatingCenterWithDifferentLoanOfficerUpdatesAllChildrenInHierarchyIncludingTheirAssociatedLoansSavingsAndCustomerAccounts() throws Exception {
// setup
String externalId = center.getExternalId();
String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(center.getMfiJoiningDate());
AddressDto address = null;
if (center.getAddress() != null) {
address = Address.toDto(center.getAddress());
}
List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), otherLoanOfficer.getPersonnelId(), externalId, mfiJoiningDate, address, customFields, customerPositions);
UserContext userContext = TestUtils.makeUser();
// exercise test
customerService.updateCenter(userContext, centerUpdate);
StaticHibernateUtil.flushAndClearSession();
// verification
center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
group = customerDao.findGroupBySystemId(group.getGlobalCustNum());
group2 = customerDao.findGroupBySystemId(group2.getGlobalCustNum());
assertThat(center.getDisplayName(), is(updatedDisplayName));
assertThat(center.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
assertThat(group.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
assertThat(group2.getPersonnel().getDisplayName(), is(otherLoanOfficer.getDisplayName()));
}
use of org.mifos.dto.domain.AddressDto in project head by mifos.
the class CenterUpdateUsingCustomerServiceIntegrationTest method canUpdateCenterWithDifferentMfiJoiningDateInPastOrFuture.
@Test
public void canUpdateCenterWithDifferentMfiJoiningDateInPastOrFuture() throws Exception {
// setup
Short loanOfficerId = center.getPersonnel().getPersonnelId();
String externalId = center.getExternalId();
LocalDate dateInPast = new LocalDate(center.getMfiJoiningDate()).minusWeeks(4);
String mfiJoiningDate = new SimpleDateFormat("dd/MM/yyyy").format(dateInPast.toDateMidnight().toDate());
AddressDto address = null;
if (center.getAddress() != null) {
address = Address.toDto(center.getAddress());
}
List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
List<CustomerPositionDto> customerPositions = new ArrayList<CustomerPositionDto>();
String updatedDisplayName = "Center " + RandomStringUtils.randomAlphanumeric(5);
CenterUpdate centerUpdate = new CenterUpdate(center.getCustomerId(), updatedDisplayName, center.getVersionNo(), loanOfficerId, externalId, mfiJoiningDate, address, customFields, customerPositions);
UserContext userContext = TestUtils.makeUser();
// exercise test
customerService.updateCenter(userContext, centerUpdate);
// verification
center = customerDao.findCenterBySystemId(center.getGlobalCustNum());
assertThat(center.getMfiJoiningDate(), is(dateInPast.toDateMidnight().toDate()));
}
use of org.mifos.dto.domain.AddressDto in project head by mifos.
the class PersonnelServiceFacadeWebTier method updatePersonnel.
@Override
public UserDetailDto updatePersonnel(CreateOrUpdatePersonnelInformation personnel) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PersonnelBO userForUpdate = this.personnelDao.findPersonnelById(personnel.getId().shortValue());
userForUpdate.updateDetails(userContext);
AddressDto addressDto = personnel.getAddress();
Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
PersonnelStatus status = PersonnelStatus.getPersonnelStatus(personnel.getPersonnelStatusId());
PersonnelLevel userHierarchyLevel = PersonnelLevel.fromInt(personnel.getPersonnelLevelId().intValue());
OfficeBO newOffice = this.officeDao.findOfficeById(personnel.getOfficeId());
validateForUpdate(userForUpdate, status, newOffice, userHierarchyLevel);
List<RoleBO> selectedRoles = new ArrayList<RoleBO>();
try {
List<RoleBO> allRoles = new PersonnelBusinessService().getRoles();
for (RoleBO role : allRoles) {
if (isRoleSelected(role, personnel.getRoles())) {
selectedRoles.add(role);
}
}
PersonnelStatusEntity personnelStatus = legacyMasterDao.getPersistentObject(PersonnelStatusEntity.class, status.getValue());
PersonnelLevelEntity personnelLevel = legacyMasterDao.getPersistentObject(PersonnelLevelEntity.class, userHierarchyLevel.getValue());
Short preferredLocaleId = personnel.getPreferredLocale();
transactionHelper.startTransaction();
transactionHelper.beginAuditLoggingFor(userForUpdate);
userForUpdate.updateUserDetails(personnel.getFirstName(), personnel.getMiddleName(), personnel.getSecondLastName(), personnel.getLastName(), personnel.getEmailId(), personnel.getGender(), personnel.getMaritalStatus(), preferredLocaleId, personnelStatus, address, personnel.getTitle(), personnelLevel, selectedRoles, newOffice);
userForUpdate.getPersonnelDetails().setDob(personnel.getDob().toDate());
userForUpdate.setPasswordExpirationDate(personnel.getPasswordExpirationDate().toDate());
if (!StringUtils.isEmpty(personnel.getPassword())) {
this.personelService.changePassword(userForUpdate, personnel.getPassword(), false);
}
this.personnelDao.save(userForUpdate);
transactionHelper.commitTransaction();
return userForUpdate.toDto();
} catch (BusinessRuleException e) {
transactionHelper.rollbackTransaction();
throw e;
} catch (PersistenceException e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (Exception e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
transactionHelper.closeSession();
}
}
Aggregations