use of org.mifos.customers.personnel.util.helpers.PersonnelStatus in project head by mifos.
the class PersonAction method translateFormToCreatePersonnelInformationDto.
@SuppressWarnings("unchecked")
private CreateOrUpdatePersonnelInformation translateFormToCreatePersonnelInformationDto(HttpServletRequest request, PersonActionForm personActionForm) throws PageExpiredException, InvalidDateException {
UserContext userContext = getUserContext(request);
PersonnelLevel level = PersonnelLevel.fromInt(getShortValue(personActionForm.getLevel()));
PersonnelStatus personnelStatus = PersonnelStatus.ACTIVE;
if (StringUtils.isNotBlank(personActionForm.getStatus())) {
personnelStatus = PersonnelStatus.getPersonnelStatus(getShortValue(personActionForm.getStatus()));
}
OfficeBO office = (OfficeBO) SessionUtils.getAttribute(PersonnelConstants.OFFICE, request);
if (office == null) {
Short officeId = getShortValue(personActionForm.getOfficeId());
office = this.officeDao.findOfficeById(officeId);
}
Integer title = getIntegerValue(personActionForm.getTitle());
Short preferredLocale = Localization.getInstance().getConfiguredLocaleId();
preferredLocale = getPerefferedLocale(personActionForm, userContext);
Date dob = null;
if (personActionForm.getDob() != null && !personActionForm.getDob().equals("")) {
dob = DateUtils.getDate(personActionForm.getDob());
}
Date dateOfJoiningMFI = null;
if (personActionForm.getDateOfJoiningMFI() != null && !personActionForm.getDateOfJoiningMFI().equals("")) {
dateOfJoiningMFI = DateUtils.getDateAsSentFromBrowser(personActionForm.getDateOfJoiningMFI());
}
Date passwordExpirationDate = null;
if (personActionForm.getPasswordExpirationDate() != null && !personActionForm.getPasswordExpirationDate().equals("")) {
passwordExpirationDate = DateUtils.getDate(personActionForm.getPasswordExpirationDate());
}
List<RoleBO> roles = new ArrayList<RoleBO>();
boolean addFlag = false;
List<RoleBO> selectList = new ArrayList<RoleBO>();
List<RoleBO> masterList = (List<RoleBO>) SessionUtils.getAttribute(PersonnelConstants.ROLEMASTERLIST, request);
if (personActionForm.getPersonnelRoles() != null) {
for (RoleBO role : masterList) {
for (String roleId : personActionForm.getPersonnelRoles()) {
if (roleId != null && role.getId().intValue() == Integer.valueOf(roleId).intValue()) {
selectList.add(role);
addFlag = true;
}
}
}
}
if (addFlag) {
roles = selectList;
}
List<ListElement> roleList = new ArrayList<ListElement>();
for (RoleBO element : roles) {
ListElement listElement = new ListElement(new Integer(element.getId()), element.getName());
roleList.add(listElement);
}
Address address = personActionForm.getAddress();
AddressDto addressDto = new AddressDto(address.getLine1(), address.getLine2(), address.getLine3(), address.getCity(), address.getState(), address.getCountry(), address.getZip(), address.getPhoneNumber());
Long id = null;
if (StringUtils.isNotBlank(personActionForm.getPersonnelId())) {
id = Long.valueOf(personActionForm.getPersonnelId());
}
CreateOrUpdatePersonnelInformation perosonnelInfo = new CreateOrUpdatePersonnelInformation(id, level.getValue(), office.getOfficeId(), title, preferredLocale, personActionForm.getUserPassword(), personActionForm.getLoginName(), personActionForm.getEmailId(), roleList, personActionForm.getCustomFields(), personActionForm.getFirstName(), personActionForm.getMiddleName(), personActionForm.getLastName(), personActionForm.getSecondLastName(), personActionForm.getGovernmentIdNumber(), new DateTime(dob), getIntegerValue(personActionForm.getMaritalStatus()), getIntegerValue(personActionForm.getGender()), new DateTime(dateOfJoiningMFI), new DateTimeService().getCurrentDateTime(), addressDto, personnelStatus.getValue(), new DateTime(passwordExpirationDate));
return perosonnelInfo;
}
use of org.mifos.customers.personnel.util.helpers.PersonnelStatus 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