Search in sources :

Example 1 with ClientFamilyDetailOtherDto

use of org.mifos.dto.screen.ClientFamilyDetailOtherDto in project head by mifos.

the class CustomerDaoHibernate method getClientDisplayDto.

@SuppressWarnings("unchecked")
@Override
public ClientDisplayDto getClientDisplayDto(Integer clientId, UserContext userContext) {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("CLIENT_ID", clientId);
    List<Object[]> queryResult = (List<Object[]>) this.genericDao.executeNamedQuery("getClientDisplayDto", queryParameters);
    if (queryResult.size() == 0) {
        throw new MifosRuntimeException("Client not found: " + clientId);
    }
    if (queryResult.size() > 1) {
        throw new MifosRuntimeException("Error finding Client id: " + clientId + " - Number found: " + queryResult.size());
    }
    final Integer customerId = (Integer) queryResult.get(0)[0];
    final String globalCustNum = (String) queryResult.get(0)[1];
    final String displayName = (String) queryResult.get(0)[2];
    final String parentCustomerDisplayName = (String) queryResult.get(0)[3];
    final String branchName = (String) queryResult.get(0)[4];
    final String externalId = (String) queryResult.get(0)[5];
    final String customerFormedByDisplayName = (String) queryResult.get(0)[6];
    final Date customerActivationDate = (Date) queryResult.get(0)[7];
    final Short customerLevelId = (Short) queryResult.get(0)[8];
    final Short customerStatusId = (Short) queryResult.get(0)[9];
    final String lookupName = (String) queryResult.get(0)[10];
    final Date trainedDate = (Date) queryResult.get(0)[11];
    final Date dateOfBirth = (Date) queryResult.get(0)[12];
    final String governmentId = (String) queryResult.get(0)[13];
    final Short groupFlag = (Short) queryResult.get(0)[14];
    final Boolean blackListed = (Boolean) queryResult.get(0)[15];
    final Short loanOfficerId = (Short) queryResult.get(0)[16];
    final String loanOfficerName = (String) queryResult.get(0)[17];
    final String businessActivitiesName = (String) queryResult.get(0)[18];
    final String handicappedName = (String) queryResult.get(0)[19];
    final String maritalStatusName = (String) queryResult.get(0)[20];
    final String citizenshipName = (String) queryResult.get(0)[21];
    final String ethnicityName = (String) queryResult.get(0)[22];
    final String educationLevelName = (String) queryResult.get(0)[23];
    final String povertyStatusName = (String) queryResult.get(0)[24];
    final Short numChildren = (Short) queryResult.get(0)[25];
    final Integer branchId = (Integer) queryResult.get(0)[26];
    Boolean clientUnderGroup = false;
    if (groupFlag.compareTo(Short.valueOf("0")) > 0) {
        clientUnderGroup = true;
    }
    final String customerStatusName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupName);
    final String businessActivities = ApplicationContextProvider.getBean(MessageLookup.class).lookup(businessActivitiesName);
    final String handicapped = ApplicationContextProvider.getBean(MessageLookup.class).lookup(handicappedName);
    final String maritalStatus = ApplicationContextProvider.getBean(MessageLookup.class).lookup(maritalStatusName);
    final String citizenship = ApplicationContextProvider.getBean(MessageLookup.class).lookup(citizenshipName);
    final String ethnicity = ApplicationContextProvider.getBean(MessageLookup.class).lookup(ethnicityName);
    final String educationLevel = ApplicationContextProvider.getBean(MessageLookup.class).lookup(educationLevelName);
    final String povertyStatus = ApplicationContextProvider.getBean(MessageLookup.class).lookup(povertyStatusName);
    String spouseFatherValue = null;
    String spouseFatherName = null;
    List<ClientFamilyDetailOtherDto> familyDetails = null;
    Boolean areFamilyDetailsRequired = ClientRules.isFamilyDetailsRequired();
    if (areFamilyDetailsRequired) {
        familyDetails = new ArrayList<ClientFamilyDetailOtherDto>();
        List<Object[]> familyDetailsQueryResult = (List<Object[]>) this.genericDao.executeNamedQuery("getClientFamilyDetailDto", queryParameters);
        for (Object[] familyDetail : familyDetailsQueryResult) {
            final String relationshipLookup = (String) familyDetail[0];
            final String familyDisplayName = (String) familyDetail[1];
            final Date familyDateOfBirth = (Date) familyDetail[2];
            final String genderLookup = (String) familyDetail[3];
            final String livingStatusLookup = (String) familyDetail[4];
            final String relationship = ApplicationContextProvider.getBean(MessageLookup.class).lookup(relationshipLookup);
            final String gender = ApplicationContextProvider.getBean(MessageLookup.class).lookup(genderLookup);
            final String livingStatus = ApplicationContextProvider.getBean(MessageLookup.class).lookup(livingStatusLookup);
            String dateOfBirthAsString = "";
            if (familyDateOfBirth != null) {
                dateOfBirthAsString = DateUtils.makeDateAsSentFromBrowser(familyDateOfBirth);
            }
            familyDetails.add(new ClientFamilyDetailOtherDto(relationship, familyDisplayName, familyDateOfBirth, gender, livingStatus, dateOfBirthAsString));
        }
    } else {
        List<Object[]> clientNameDetailsQueryResult = (List<Object[]>) this.genericDao.executeNamedQuery("getClientNameDetailDto", queryParameters);
        if (clientNameDetailsQueryResult.size() > 0) {
            final String spouseFatherValueLookUp = (String) clientNameDetailsQueryResult.get(0)[0];
            spouseFatherName = (String) clientNameDetailsQueryResult.get(0)[1];
            spouseFatherValue = ApplicationContextProvider.getBean(MessageLookup.class).lookup(spouseFatherValueLookUp);
        }
    }
    Integer age = null;
    if (dateOfBirth != null) {
        age = DateUtils.DateDiffInYears(new java.sql.Date(dateOfBirth.getTime()));
    }
    return new ClientDisplayDto(customerId, globalCustNum, displayName, parentCustomerDisplayName, branchId, branchName, externalId, customerFormedByDisplayName, customerActivationDate, customerLevelId, customerStatusId, customerStatusName, trainedDate, dateOfBirth, governmentId, clientUnderGroup, blackListed, loanOfficerId, loanOfficerName, businessActivities, handicapped, maritalStatus, citizenship, ethnicity, educationLevel, povertyStatus, numChildren, areFamilyDetailsRequired, spouseFatherValue, spouseFatherName, familyDetails, age);
}
Also used : ClientDisplayDto(org.mifos.dto.screen.ClientDisplayDto) HashMap(java.util.HashMap) Date(java.util.Date) BigInteger(java.math.BigInteger) ClientFamilyDetailOtherDto(org.mifos.dto.screen.ClientFamilyDetailOtherDto) MessageLookup(org.mifos.application.master.MessageLookup) ArrayList(java.util.ArrayList) List(java.util.List) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MessageLookup (org.mifos.application.master.MessageLookup)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 ClientDisplayDto (org.mifos.dto.screen.ClientDisplayDto)1 ClientFamilyDetailOtherDto (org.mifos.dto.screen.ClientFamilyDetailOtherDto)1