use of org.mifos.dto.domain.CreateOrUpdatePersonnelInformation in project head by mifos.
the class PersonAction method create.
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
PersonActionForm personActionForm = (PersonActionForm) form;
CreateOrUpdatePersonnelInformation perosonnelInfo = translateFormToCreatePersonnelInformationDto(request, personActionForm);
try {
UserDetailDto userDetails = this.personnelServiceFacade.createPersonnelInformation(perosonnelInfo);
String globalPersonnelNum = userDetails.getSystemId();
Name name = new Name(personActionForm.getFirstName(), personActionForm.getMiddleName(), personActionForm.getSecondLastName(), personActionForm.getLastName());
request.setAttribute("displayName", name.getDisplayName());
request.setAttribute("globalPersonnelNum", globalPersonnelNum);
createGroupQuestionnaire.saveResponses(request, personActionForm, userDetails.getId());
return mapping.findForward(ActionForwards.create_success.toString());
} catch (BusinessRuleException e) {
throw new PersonnelException(e.getMessageKey(), e, e.getMessageValues());
}
}
use of org.mifos.dto.domain.CreateOrUpdatePersonnelInformation in project head by mifos.
the class SystemUserController method updateUser.
public void updateUser(final UserFormBean userFormBean) {
CreateOrUpdatePersonnelInformation personnel = translateUserFormBeanToDto(userFormBean);
this.personnelServiceFacade.updatePersonnel(personnel);
}
use of org.mifos.dto.domain.CreateOrUpdatePersonnelInformation 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.dto.domain.CreateOrUpdatePersonnelInformation in project head by mifos.
the class PersonAction method update.
@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
PersonActionForm actionForm = (PersonActionForm) form;
try {
CreateOrUpdatePersonnelInformation perosonnelInfo = translateFormToCreatePersonnelInformationDto(request, actionForm);
UserDetailDto userDetails = this.personnelServiceFacade.updatePersonnel(perosonnelInfo);
String globalPersonnelNum = userDetails.getSystemId();
Name name = new Name(actionForm.getFirstName(), actionForm.getMiddleName(), actionForm.getSecondLastName(), actionForm.getLastName());
request.setAttribute("displayName", name.getDisplayName());
request.setAttribute("globalPersonnelNum", globalPersonnelNum);
//refresh user context roles if active
Set<Short> roles = new HashSet<Short>();
for (ListElement userNewRole : perosonnelInfo.getRoles()) {
roles.add(userNewRole.getId().shortValue());
}
refreshUserContextIfActive(request, perosonnelInfo.getId(), perosonnelInfo.getUserName(), roles);
return mapping.findForward(ActionForwards.update_success.toString());
} catch (BusinessRuleException e) {
throw new PersonnelException(e.getMessageKey(), e.getMessageValues());
}
}
use of org.mifos.dto.domain.CreateOrUpdatePersonnelInformation 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;
}
Aggregations