Search in sources :

Example 6 with UserDetailDto

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

the class HomePageController method showPopulatedForm.

@RequestMapping(method = RequestMethod.GET)
@ModelAttribute("customerSearch")
public ModelAndView showPopulatedForm(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("customerSearch") CustomerSearchFormBean customerSearchFormBean) throws MifosException, PersistenceException {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    ModelAndView modelAndView = new ModelAndView();
    sitePreferenceHelper.resolveSiteType(modelAndView, "home", request);
    modelAndView.addObject("include_page", new IncludePage(request, response));
    Short userId = (short) user.getUserId();
    UserDetailDto userDetails = this.centerServiceFacade.retrieveUsersDetails(userId);
    modelAndView.addObject("customerSearch", customerSearchFormBean);
    boolean isCenterHierarchyExists = configurationServiceFacade.getBooleanConfig("ClientRules.CenterHierarchyExists");
    modelAndView.addObject("isCenterHierarchyExists", isCenterHierarchyExists);
    if (sitePreferenceHelper.isMobile(request)) {
        List<ValueListElement> availibleClientGenders = clientServiceFacade.getClientGenders();
        modelAndView.addObject("availibleClientGenders", availibleClientGenders);
        HashMap<String, ArrayList<CustomerStatusDetailDto>> customerStates = new HashMap<String, ArrayList<CustomerStatusDetailDto>>();
        customerStates.putAll(customerSearchServiceFacade.getAvailibleCustomerStates());
        modelAndView.addObject("availibleCustomerStates", customerStates);
    }
    if (userDetails.isLoanOfficer()) {
        loadLoanOfficerCustomersHierarchyForSelectedDay(userId, modelAndView, customerSearchFormBean);
        modelAndView.addObject("isLoanOfficer", true);
    } else {
        modelAndView.addObject("isLoanOfficer", false);
    }
    return modelAndView;
}
Also used : CustomerStatusDetailDto(org.mifos.dto.screen.CustomerStatusDetailDto) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserDetailDto(org.mifos.dto.domain.UserDetailDto) IncludePage(freemarker.ext.servlet.IncludePage) ValueListElement(org.mifos.dto.domain.ValueListElement) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with UserDetailDto

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

the class PersonnelDaoHibernate method search.

@SuppressWarnings("unchecked")
@Override
public SystemUserSearchResultsDto search(UserSearchDto searchDto, MifosUser user) {
    Short userId = Integer.valueOf(user.getUserId()).shortValue();
    PersonnelBO loggedInUser = findPersonnelById(userId);
    final PersonnelLevel level = loggedInUser.getLevelEnum();
    final String searchAllSubOfficesInclusiveOfLoggedInUserOffice = loggedInUser.getOfficeSearchId() + "%";
    final String searchString = org.mifos.framework.util.helpers.SearchUtils.normalizeSearchString(searchDto.getSearchTerm());
    final String username = searchString + "%";
    String firstName = "";
    String secondPartOfName = "";
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("SEARCH_ALL", searchAllSubOfficesInclusiveOfLoggedInUserOffice);
    queryParameters.put("USERID", userId);
    queryParameters.put("LOID", PersonnelLevel.LOAN_OFFICER.getValue());
    queryParameters.put("USERLEVEL_ID", level.getValue());
    queryParameters.put("USER_NAME", username);
    if (searchString.contains(" ")) {
        firstName = searchString.substring(0, searchString.indexOf(" "));
        secondPartOfName = searchString.substring(searchString.indexOf(" ") + 1, searchString.length());
        queryParameters.put("USER_NAME1", firstName);
        queryParameters.put("USER_NAME2", secondPartOfName);
    } else {
        firstName = searchString;
        secondPartOfName = "";
        queryParameters.put("USER_NAME1", searchString);
        queryParameters.put("USER_NAME2", "");
    }
    Long searchResultsCount = (Long) this.genericDao.executeUniqueResultNamedQuery(NamedQueryConstants.PERSONNEL_SEARCH_COUNT, queryParameters);
    Session session = StaticHibernateUtil.getSessionTL();
    Criteria criteriaQuery = session.createCriteria(PersonnelBO.class);
    criteriaQuery.createAlias("office", "o");
    criteriaQuery.createAlias("personnelDetails", "d");
    if (PersonnelLevel.LOAN_OFFICER.getValue().equals(Short.valueOf("2"))) {
        criteriaQuery.add(Restrictions.eq("personnelId", userId));
    }
    criteriaQuery.add(Restrictions.like("o.searchId", searchAllSubOfficesInclusiveOfLoggedInUserOffice));
    LogicalExpression firstOrLastNameMatchUsername = Restrictions.or(Restrictions.like("d.name.firstName", username), Restrictions.like("d.name.lastName", username));
    LogicalExpression firstNameAndLastNameMatchGivenParts = Restrictions.and(Restrictions.like("d.name.firstName", firstName), Restrictions.like("d.name.lastName", secondPartOfName));
    criteriaQuery.add(Restrictions.or(firstOrLastNameMatchUsername, firstNameAndLastNameMatchGivenParts));
    criteriaQuery.addOrder(Order.asc("o.officeName"));
    criteriaQuery.addOrder(Order.asc("d.name.lastName"));
    criteriaQuery.setFetchMode("office", FetchMode.JOIN);
    criteriaQuery.setFetchMode("level", FetchMode.JOIN);
    criteriaQuery.setFetchMode("personnelDetails", FetchMode.JOIN);
    int firstResult = (searchDto.getPage() * searchDto.getPageSize()) - searchDto.getPageSize();
    criteriaQuery.setFirstResult(firstResult);
    criteriaQuery.setMaxResults(searchDto.getPageSize());
    List<PersonnelBO> pagedResults = criteriaQuery.list();
    List<UserDetailDto> pagedUserDetails = new ArrayList<UserDetailDto>();
    for (PersonnelBO personnelBO : pagedResults) {
        pagedUserDetails.add(personnelBO.toDto());
    }
    SystemUserSearchResultsDto resultsDto = new SystemUserSearchResultsDto(searchResultsCount.intValue(), firstResult, searchDto.getPage(), searchDto.getPageSize(), pagedUserDetails);
    return resultsDto;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) LogicalExpression(org.hibernate.criterion.LogicalExpression) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserDetailDto(org.mifos.dto.domain.UserDetailDto) PersonnelLevel(org.mifos.customers.personnel.util.helpers.PersonnelLevel) SystemUserSearchResultsDto(org.mifos.dto.screen.SystemUserSearchResultsDto) Session(org.hibernate.Session)

Example 8 with UserDetailDto

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

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

the class CustSearchAction method loadMasterData.

private String loadMasterData(Short userId, HttpServletRequest request, CustSearchActionForm form) throws Exception {
    UserDetailDto userDetails = this.centerServiceFacade.retrieveUsersDetails(userId);
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel(userId);
    SessionUtils.setAttribute(CustomerSearchConstants.OFFICE, userDetails.getOfficeName(), request);
    if (userDetails.isLoanOfficer()) {
        SessionUtils.setAttribute("isLoanOfficer", true, request);
        return loadLoanOfficer(personnel, request);
    }
    SessionUtils.setAttribute("isLoanOfficer", false, request);
    return loadNonLoanOfficer(personnel, request, form);
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) UserDetailDto(org.mifos.dto.domain.UserDetailDto)

Example 10 with UserDetailDto

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

the class ClientsAndAccountsPageController method showClientsAndAccountsMainSearch.

@SuppressWarnings("PMD.AvoidUsingShortType")
public ModelAndView showClientsAndAccountsMainSearch(HttpServletRequest request, CustomerSearchFormBean customerSearchFormBean, ModelAndView modelAndView) {
    sitePreferenceHelper.resolveSiteType(modelAndView, "clientsAndAccounts", request);
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Short userId = (short) user.getUserId();
    UserDetailDto userDetails = this.centerServiceFacade.retrieveUsersDetails(userId);
    List<OfficeDto> officeDtoList = officeServiceFacade.retrieveActiveBranchesUnderUser(userId);
    Map<String, String> officesMap = new HashMap<String, String>();
    for (OfficeDto officeDto : officeDtoList) {
        officesMap.put(officeDto.getId().toString(), officeDto.getName());
    }
    customerSearchFormBean.setOffices(officesMap);
    customerSearchFormBean.setOfficeName(userDetails.getOfficeName());
    return modelAndView;
}
Also used : OfficeDto(org.mifos.dto.domain.OfficeDto) HashMap(java.util.HashMap) UserDetailDto(org.mifos.dto.domain.UserDetailDto) MifosUser(org.mifos.security.MifosUser)

Aggregations

UserDetailDto (org.mifos.dto.domain.UserDetailDto)10 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)4 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)3 ValueListElement (org.mifos.dto.domain.ValueListElement)3 MifosUser (org.mifos.security.MifosUser)3 PersonnelException (org.mifos.customers.personnel.exceptions.PersonnelException)2 PersonActionForm (org.mifos.customers.personnel.struts.actionforms.PersonActionForm)2 CreateOrUpdatePersonnelInformation (org.mifos.dto.domain.CreateOrUpdatePersonnelInformation)2 CustomerStatusDetailDto (org.mifos.dto.screen.CustomerStatusDetailDto)2 SystemUserSearchResultsDto (org.mifos.dto.screen.SystemUserSearchResultsDto)2 Name (org.mifos.framework.business.util.Name)2 BusinessRuleException (org.mifos.service.BusinessRuleException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 IncludePage (freemarker.ext.servlet.IncludePage)1 HashSet (java.util.HashSet)1 Criteria (org.hibernate.Criteria)1 Session (org.hibernate.Session)1