Search in sources :

Example 21 with AddressDto

use of org.mifos.dto.domain.AddressDto in project head by mifos.

the class OfficeServiceFacadeWebTier method createOffice.

@Override
public ListElement createOffice(Short operationMode, OfficeDto officeDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    OfficeLevel level = OfficeLevel.getOfficeLevel(officeDto.getLevelId());
    OfficeBO parentOffice = officeDao.findOfficeById(officeDto.getParentId());
    AddressDto addressDto = officeDto.getAddress();
    Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
    try {
        OfficeBO officeBO = new OfficeBO(userContext, level, parentOffice, officeDto.getCustomFields(), officeDto.getName(), officeDto.getOfficeShortName(), address, OperationMode.fromInt(operationMode.intValue()));
        OfficePersistence officePersistence = new OfficePersistence();
        if (officePersistence.isOfficeNameExist(officeDto.getName())) {
            throw new OfficeValidationException(OfficeConstants.OFFICENAMEEXIST);
        }
        if (officePersistence.isOfficeShortNameExist(officeDto.getOfficeShortName())) {
            throw new OfficeValidationException(OfficeConstants.OFFICESHORTNAMEEXIST);
        }
        String searchId = generateSearchId(parentOffice);
        officeBO.setSearchId(searchId);
        String globalOfficeNum = generateOfficeGlobalNo();
        officeBO.setGlobalOfficeNum(globalOfficeNum);
        StaticHibernateUtil.startTransaction();
        this.officeDao.save(officeBO);
        StaticHibernateUtil.commitTransaction();
        //Shahid - this is hackish solution to return officeId and globalOfficeNum via ListElement, it should be fixed, at least
        //a proper data storage class can be created
        ListElement element = new ListElement(new Integer(officeBO.getOfficeId()), officeBO.getGlobalOfficeNum());
        // if we are here it means office created sucessfully
        // we need to update hierarchy manager cache
        OfficeSearch os = new OfficeSearch(officeBO.getOfficeId(), officeBO.getSearchId(), officeBO.getParentOffice().getOfficeId());
        List<OfficeSearch> osList = new ArrayList<OfficeSearch>();
        osList.add(os);
        EventManger.postEvent(Constants.CREATE, osList, SecurityConstants.OFFICECHANGEEVENT);
        return element;
    } catch (OfficeValidationException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BusinessRuleException(e.getMessage());
    } catch (PersistenceException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (OfficeException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) OfficeValidationException(org.mifos.customers.office.exceptions.OfficeValidationException) 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) OfficeSearch(org.mifos.security.util.OfficeSearch) AddressDto(org.mifos.dto.domain.AddressDto) BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeBO(org.mifos.customers.office.business.OfficeBO) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) OfficeLevel(org.mifos.customers.office.util.helpers.OfficeLevel) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 22 with AddressDto

use of org.mifos.dto.domain.AddressDto in project head by mifos.

the class OfficeServiceFacadeWebTier method retrieveOfficeById.

@Override
public OfficeDto retrieveOfficeById(Short id) {
    OfficeBO officeBO = officeDao.findOfficeById(id);
    List<CustomFieldDto> customFields = new ArrayList<CustomFieldDto>();
    Short parentOfficeId = null;
    String parentOffineName = null;
    if (officeBO.getParentOffice() != null) {
        parentOfficeId = officeBO.getParentOffice().getOfficeId();
        parentOffineName = officeBO.getParentOffice().getOfficeName();
    }
    Address address = officeBO.getAddress() != null ? officeBO.getAddress().getAddress() : null;
    AddressDto addressDto = address != null ? Address.toDto(officeBO.getAddress().getAddress()) : null;
    String officeLevelName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(officeBO.getLevel().getLookUpValue());
    String officeStatusName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(officeBO.getStatus().getLookUpValue());
    OfficeDto officeDto = new OfficeDto(officeBO.getOfficeId(), officeBO.getOfficeName(), officeBO.getSearchId(), officeBO.getShortName(), officeBO.getGlobalOfficeNum(), parentOfficeId, officeBO.getStatus().getId(), officeBO.getLevel().getId(), parentOffineName, officeBO.getVersionNo(), officeStatusName, officeLevelName, addressDto, customFields);
    return officeDto;
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) Address(org.mifos.framework.business.util.Address) OfficeBO(org.mifos.customers.office.business.OfficeBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) MessageLookup(org.mifos.application.master.MessageLookup) ArrayList(java.util.ArrayList) AddressDto(org.mifos.dto.domain.AddressDto)

Example 23 with AddressDto

use of org.mifos.dto.domain.AddressDto in project head by mifos.

the class CenterServiceFacadeWebTier method retrieveCenterDetailsForUpdate.

@Override
public CenterDto retrieveCenterDetailsForUpdate(Integer centerId) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    CustomerBO center = customerDao.findCustomerById(centerId);
    Short officeId = center.getOffice().getOfficeId();
    String searchId = center.getSearchId();
    Short loanOfficerId = extractLoanOfficerId(center);
    CenterCreation centerCreation = new CenterCreation(officeId, userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
    List<PersonnelDto> activeLoanOfficersForBranch = personnelDao.findActiveLoanOfficersForOffice(centerCreation);
    List<CustomerDto> customerList = customerDao.findClientsThatAreNotCancelledOrClosed(searchId, officeId);
    List<CustomerPositionDto> customerPositionDtos = generateCustomerPositionViews(center, userContext.getLocaleId());
    DateTime mfiJoiningDate = new DateTime();
    String mfiJoiningDateAsString = "";
    if (center.getMfiJoiningDate() != null) {
        mfiJoiningDate = new DateTime(center.getMfiJoiningDate());
        mfiJoiningDateAsString = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), center.getMfiJoiningDate().toString());
    }
    AddressDto address = null;
    if (center.getAddress() != null) {
        address = Address.toDto(center.getAddress());
    }
    return new CenterDto(loanOfficerId, center.getCustomerId(), center.getGlobalCustNum(), mfiJoiningDate, mfiJoiningDateAsString, center.getExternalId(), address, customerPositionDtos, customerList, activeLoanOfficersForBranch, true);
}
Also used : UserContext(org.mifos.security.util.UserContext) CustomerDto(org.mifos.dto.domain.CustomerDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) CenterDto(org.mifos.dto.domain.CenterDto) MifosUser(org.mifos.security.MifosUser) CustomerAddressDto(org.mifos.dto.domain.CustomerAddressDto) AddressDto(org.mifos.dto.domain.AddressDto) DateTime(org.joda.time.DateTime) CenterCreation(org.mifos.dto.domain.CenterCreation) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPositionDto(org.mifos.dto.domain.CustomerPositionDto)

Example 24 with AddressDto

use of org.mifos.dto.domain.AddressDto 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 25 with AddressDto

use of org.mifos.dto.domain.AddressDto in project head by mifos.

the class PictureFormFile method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    MeetingBO meeting = (MeetingBO) SessionUtils.getAttribute(CustomerConstants.CUSTOMER_MEETING, request);
    List<SavingsDetailDto> allowedSavingProducts = getSavingsOfferingsFromSession(request);
    if (ClientRules.isFamilyDetailsRequired()) {
        actionForm.setFamilyDateOfBirth();
        actionForm.constructFamilyDetails();
    }
    List<Short> selectedSavingProducts = actionForm.getSelectedOfferings();
    String clientName = actionForm.getClientName().getDisplayName();
    Short clientStatus = actionForm.getStatusValue().getValue();
    java.sql.Date mfiJoiningDate = DateUtils.getDateAsSentFromBrowser(actionForm.getMfiJoiningDate());
    String externalId = actionForm.getExternalId();
    AddressDto address = null;
    if (actionForm.getAddress() != null) {
        address = Address.toDto(actionForm.getAddress());
    }
    Short formedBy = actionForm.getFormedByPersonnelValue();
    java.sql.Date dateOfBirth = DateUtils.getDateAsSentFromBrowser(actionForm.getDateOfBirth());
    String governmentId = actionForm.getGovernmentId();
    boolean trained = isTrained(actionForm.getTrainedValue());
    java.sql.Date trainedDate = DateUtils.getDateAsSentFromBrowser(actionForm.getTrainedDate());
    Short groupFlagValue = actionForm.getGroupFlagValue();
    ClientNameDetailDto clientNameDetailDto = actionForm.getClientName();
    ClientPersonalDetailDto clientPersonalDetailDto = actionForm.getClientDetailView();
    ClientNameDetailDto spouseFatherName = actionForm.getSpouseName();
    InputStream picture = actionForm.getCustomerPicture();
    String parentGroupId = actionForm.getParentGroupId();
    List<ClientNameDetailDto> familyNames = actionForm.getFamilyNames();
    List<ClientFamilyDetailDto> familyDetails = actionForm.getFamilyDetails();
    Short loanOfficerId = actionForm.getLoanOfficerIdValue();
    Short officeId = actionForm.getOfficeIdValue();
    // only applies when status is active
    LocalDate activationDateAsToday = new LocalDate();
    ClientCreationDetail clientCreationDetail = new ClientCreationDetail(selectedSavingProducts, clientName, clientStatus, mfiJoiningDate, externalId, address, formedBy, dateOfBirth, governmentId, trained, trainedDate, groupFlagValue, clientNameDetailDto, clientPersonalDetailDto, spouseFatherName, picture, actionForm.getFeesToApply(), parentGroupId, familyNames, familyDetails, loanOfficerId, officeId, activationDateAsToday);
    MeetingDto meetingDto = null;
    if (meeting != null) {
        meetingDto = meeting.toDto();
    }
    CustomerDetailsDto clientDetails = this.clientServiceFacade.createNewClient(clientCreationDetail, meetingDto, allowedSavingProducts);
    List<FormFile> formFiles = actionForm.getFiles();
    List<UploadedFileDto> filesMetadata = actionForm.getFilesMetadata();
    for (int i = 0; i < formFiles.size(); i++) {
        if (formFiles.get(i).getFileSize() != 0) {
            InputStream inputStream = formFiles.get(i).getInputStream();
            UploadedFileDto fileMetadata = filesMetadata.get(i);
            clientServiceFacade.uploadFile(clientDetails.getId(), inputStream, fileMetadata);
        }
    }
    actionForm.setCustomerId(clientDetails.getId().toString());
    actionForm.setGlobalCustNum(clientDetails.getGlobalCustNum());
    actionForm.setEditFamily("notEdit");
    createClientQuestionnaire.saveResponses(request, actionForm, clientDetails.getId());
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) LocalDate(org.joda.time.LocalDate) FormFile(org.apache.struts.upload.FormFile) ClientCreationDetail(org.mifos.dto.domain.ClientCreationDetail) ClientFamilyDetailDto(org.mifos.dto.screen.ClientFamilyDetailDto) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto) ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) AddressDto(org.mifos.dto.domain.AddressDto) Date(java.sql.Date) MeetingDto(org.mifos.dto.domain.MeetingDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

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