Search in sources :

Example 1 with CreateOrUpdatePersonnelInformation

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());
    }
}
Also used : PersonActionForm(org.mifos.customers.personnel.struts.actionforms.PersonActionForm) BusinessRuleException(org.mifos.service.BusinessRuleException) CreateOrUpdatePersonnelInformation(org.mifos.dto.domain.CreateOrUpdatePersonnelInformation) UserDetailDto(org.mifos.dto.domain.UserDetailDto) PersonnelException(org.mifos.customers.personnel.exceptions.PersonnelException) Name(org.mifos.framework.business.util.Name) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with CreateOrUpdatePersonnelInformation

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);
}
Also used : CreateOrUpdatePersonnelInformation(org.mifos.dto.domain.CreateOrUpdatePersonnelInformation)

Example 3 with CreateOrUpdatePersonnelInformation

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;
}
Also used : Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) Date(java.util.Date) DateTime(org.joda.time.DateTime) PersonnelStatus(org.mifos.customers.personnel.util.helpers.PersonnelStatus) CreateOrUpdatePersonnelInformation(org.mifos.dto.domain.CreateOrUpdatePersonnelInformation) OfficeBO(org.mifos.customers.office.business.OfficeBO) ValueListElement(org.mifos.dto.domain.ValueListElement) ListElement(org.mifos.dto.screen.ListElement) List(java.util.List) ArrayList(java.util.ArrayList) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) DateTimeService(org.mifos.framework.util.DateTimeService) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 4 with CreateOrUpdatePersonnelInformation

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());
    }
}
Also used : PersonActionForm(org.mifos.customers.personnel.struts.actionforms.PersonActionForm) BusinessRuleException(org.mifos.service.BusinessRuleException) CreateOrUpdatePersonnelInformation(org.mifos.dto.domain.CreateOrUpdatePersonnelInformation) UserDetailDto(org.mifos.dto.domain.UserDetailDto) ValueListElement(org.mifos.dto.domain.ValueListElement) ListElement(org.mifos.dto.screen.ListElement) PersonnelException(org.mifos.customers.personnel.exceptions.PersonnelException) Name(org.mifos.framework.business.util.Name) HashSet(java.util.HashSet) CloseSession(org.mifos.framework.util.helpers.CloseSession) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 5 with CreateOrUpdatePersonnelInformation

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;
}
Also used : CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto) DateTime(org.joda.time.DateTime) CreateOrUpdatePersonnelInformation(org.mifos.dto.domain.CreateOrUpdatePersonnelInformation) ListElement(org.mifos.dto.screen.ListElement)

Aggregations

CreateOrUpdatePersonnelInformation (org.mifos.dto.domain.CreateOrUpdatePersonnelInformation)5 ListElement (org.mifos.dto.screen.ListElement)3 ArrayList (java.util.ArrayList)2 DateTime (org.joda.time.DateTime)2 PersonnelException (org.mifos.customers.personnel.exceptions.PersonnelException)2 PersonActionForm (org.mifos.customers.personnel.struts.actionforms.PersonActionForm)2 AddressDto (org.mifos.dto.domain.AddressDto)2 UserDetailDto (org.mifos.dto.domain.UserDetailDto)2 ValueListElement (org.mifos.dto.domain.ValueListElement)2 Name (org.mifos.framework.business.util.Name)2 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 OfficeBO (org.mifos.customers.office.business.OfficeBO)1 PersonnelLevel (org.mifos.customers.personnel.util.helpers.PersonnelLevel)1 PersonnelStatus (org.mifos.customers.personnel.util.helpers.PersonnelStatus)1 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)1 Address (org.mifos.framework.business.util.Address)1