Search in sources :

Example 31 with AddressDto

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;
}
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)

Example 32 with AddressDto

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

Example 33 with AddressDto

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()));
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 34 with AddressDto

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()));
}
Also used : CenterUpdate(org.mifos.dto.domain.CenterUpdate) UserContext(org.mifos.security.util.UserContext) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto) AddressDto(org.mifos.dto.domain.AddressDto) LocalDate(org.joda.time.LocalDate) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 35 with AddressDto

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();
    }
}
Also used : PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) AddressDto(org.mifos.dto.domain.AddressDto) PersonnelLevelEntity(org.mifos.customers.personnel.business.PersonnelLevelEntity) ValidationException(org.mifos.framework.exceptions.ValidationException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) PersonnelStatusEntity(org.mifos.customers.personnel.business.PersonnelStatusEntity) PersonnelStatus(org.mifos.customers.personnel.util.helpers.PersonnelStatus) BusinessRuleException(org.mifos.service.BusinessRuleException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

AddressDto (org.mifos.dto.domain.AddressDto)37 ArrayList (java.util.ArrayList)24 DateTime (org.joda.time.DateTime)16 Address (org.mifos.framework.business.util.Address)16 UserContext (org.mifos.security.util.UserContext)16 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 OfficeBO (org.mifos.customers.office.business.OfficeBO)13 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)12 CustomerDetailsDto (org.mifos.dto.domain.CustomerDetailsDto)11 MeetingDto (org.mifos.dto.domain.MeetingDto)10 MifosUser (org.mifos.security.MifosUser)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 LocalDate (org.joda.time.LocalDate)8 Test (org.junit.Test)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 CustomerPositionDto (org.mifos.dto.domain.CustomerPositionDto)8 CenterUpdate (org.mifos.dto.domain.CenterUpdate)7 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)7 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)7