Example usage for org.apache.commons.lang StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfEmpty.

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

Usage

From source file:org.kafka.event.microaggregator.core.DataUtils.java

public static String makeCombinedAnswerSeq(int sequence) {
    return StringUtils.defaultIfEmpty(formatedAnswerSeq.get(String.valueOf(sequence)),
            String.valueOf(sequence));
}

From source file:org.kuali.kfs.gl.businessobject.CollectorDetail.java

public void setFromFileForCollectorDetail(String detailLine, Map<String, String> accountRecordBalanceTypeMap,
        Date curDate, UniversityDate universityDate, int lineNumber, MessageMap messageMap) {

    try {//from w ww.  j  a  v  a 2 s  . c o  m

        final Map<String, Integer> pMap = getCollectorDetailFieldUtil().getFieldBeginningPositionMap();

        detailLine = org.apache.commons.lang.StringUtils.rightPad(detailLine,
                GeneralLedgerConstants.getSpaceAllCollectorDetailFields().length(), ' ');

        setCreateDate(curDate);
        if (!GeneralLedgerConstants.getSpaceUniversityFiscalYear()
                .equals(detailLine.substring(pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                        pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)))) {
            try {
                setUniversityFiscalYear(
                        new Integer(getValue(detailLine, pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                                pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE))));
            } catch (NumberFormatException e) {
                messageMap.putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_CUSTOM,
                        "Collector detail university fiscal year " + lineNumber + " string "
                                + detailLine.substring(pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                                        pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)));
                setUniversityFiscalYear(null);
            }
        } else {
            setUniversityFiscalYear(null);
        }

        if (!GeneralLedgerConstants.getSpaceChartOfAccountsCode()
                .equals(detailLine.substring(pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                        pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE))))
            setChartOfAccountsCode(getValue(detailLine, pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE),
                    pMap.get(KFSPropertyConstants.ACCOUNT_NUMBER)));
        else
            setChartOfAccountsCode(GeneralLedgerConstants.getSpaceChartOfAccountsCode());
        setAccountNumber(getValue(detailLine, pMap.get(KFSPropertyConstants.ACCOUNT_NUMBER),
                pMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER)));

        // if chart code is empty while accounts cannot cross charts, then derive chart code from account number
        AccountService acctserv = SpringContext.getBean(AccountService.class);
        if (StringUtils.isEmpty(getChartOfAccountsCode()) && StringUtils.isNotEmpty(getAccountNumber())
                && !acctserv.accountsCanCrossCharts()) {
            Account account = acctserv.getUniqueAccountForAccountNumber(getAccountNumber());
            if (account != null) {
                setChartOfAccountsCode(account.getChartOfAccountsCode());
            }
        }

        setSubAccountNumber(getValue(detailLine, pMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER),
                pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE)));
        setFinancialObjectCode(getValue(detailLine, pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE),
                pMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE)));
        setFinancialSubObjectCode(getValue(detailLine, pMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE),
                pMap.get(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE)));

        // We are in Collector Detail for ID Billing Details because the value from file positions 26, 27 = DT.  We don not want to set Financial Balance Type Code to detail type code (DT)   
        // Generate the account record key to retrieve the balance type from the map which contains the balance type from the accounting record/origin entry
        String accountRecordKey = generateAccountRecordBalanceTypeKey();
        String financialBalanceTypeCode = accountRecordBalanceTypeMap.get(accountRecordKey);
        // Default to "AC" if we do not find account record key record from the map
        setFinancialBalanceTypeCode(StringUtils.defaultIfEmpty(financialBalanceTypeCode,
                GeneralLedgerConstants.FINALNCIAL_BALANCE_TYPE_FOR_COLLECTOR_DETAIL_RECORD));
        setFinancialObjectTypeCode(
                getValue(detailLine, pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE),
                        pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_SEQUENCE_NUMBER)));
        setUniversityFiscalPeriodCode(universityDate.getUniversityFiscalAccountingPeriod());
        setCollectorDetailSequenceNumber(
                getValue(detailLine, pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_SEQUENCE_NUMBER),
                        pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE)));
        setFinancialDocumentTypeCode(
                getValue(detailLine, pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE),
                        pMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE)));
        setFinancialSystemOriginationCode(
                getValue(detailLine, pMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE),
                        pMap.get(KFSPropertyConstants.DOCUMENT_NUMBER)));
        setDocumentNumber(getValue(detailLine, pMap.get(KFSPropertyConstants.DOCUMENT_NUMBER),
                pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_AMOUNT)));
        try {
            setCollectorDetailItemAmount(
                    getValue(detailLine, pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_AMOUNT),
                            pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_GL_CREDIT_CODE)));
        } catch (NumberFormatException e) {
            setCollectorDetailItemAmount(KualiDecimal.ZERO);
            messageMap.putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_CUSTOM,
                    "Collector detail amount cannot be parsed on line " + lineNumber + " amount string "
                            + detailLine.substring(pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_AMOUNT),
                                    pMap.get(KFSPropertyConstants.GL_CREDIT_CODE)));
        }
        if (KFSConstants.GL_CREDIT_CODE.equalsIgnoreCase(
                getValue(detailLine, pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_GL_CREDIT_CODE),
                        pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_NOTE_TEXT)))) {
            setCollectorDetailItemAmount(getCollectorDetailItemAmount().negated());
        }
        setCollectorDetailNoteText(
                getValue(detailLine, pMap.get(KFSPropertyConstants.COLLECTOR_DETAIL_NOTE_TEXT),
                        GeneralLedgerConstants.getSpaceAllCollectorDetailFields().length()));

        if (org.apache.commons.lang.StringUtils.isEmpty(getSubAccountNumber())) {
            setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
        }
        if (org.apache.commons.lang.StringUtils.isEmpty(getFinancialSubObjectCode())) {
            setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
        }
        if (org.apache.commons.lang.StringUtils.isEmpty(getCollectorDetailSequenceNumber())) {
            setCollectorDetailSequenceNumber(" ");
        }
    } catch (Exception e) {
        throw new RuntimeException(e + " occurred in CollectorDetail.setFromFileForCollectorDetail()");
    }
}

From source file:org.kuali.kfs.module.cam.util.distribution.AssetPaymentDistributionByTotalCost.java

/**
 * Doing the re-distribution of the cost based on the previous total cost of each asset compared with the total previous cost of
 * the assets.//from   w w  w. ja v a2 s . co m
 * 
 * @param detailSize
 * @param totalHistoricalCost
 * @param assetPaymentAssetDetail
 * @return
 */
private Double getAssetDetailPercentage(int detailSize, Double totalHistoricalCost,
        AssetPaymentAssetDetail assetPaymentAssetDetail) {
    Double previousTotalCostAmount = new Double("0");
    if (assetPaymentAssetDetail.getPreviousTotalCostAmount() != null) {
        previousTotalCostAmount = new Double(StringUtils
                .defaultIfEmpty(assetPaymentAssetDetail.getPreviousTotalCostAmount().toString(), "0"));
    }

    Double percentage = new Double(0);
    if (totalHistoricalCost.compareTo(new Double(0)) != 0)
        percentage = (previousTotalCostAmount / totalHistoricalCost);
    else
        percentage = (1 / (new Double(detailSize)));
    return percentage;
}

From source file:org.kuali.kfs.module.purap.service.impl.PdpExtractServiceImpl.java

/**
 * Add accounts to a PDP Payment Detail//from www  .  ja v a 2s.  co  m
 *
 * @param accountsPayableDocument
 * @param paymentDetail
 * @param documentType
 */
protected void addAccounts(AccountsPayableDocument accountsPayableDocument, PaymentDetail paymentDetail,
        String documentType) {
    String creditMemoDocType = getDataDictionaryService()
            .getDocumentTypeNameByClass(VendorCreditMemoDocument.class);
    List<SourceAccountingLine> sourceAccountingLines = purapAccountingService
            .generateSourceAccountsForVendorRemit(accountsPayableDocument);
    for (SourceAccountingLine sourceAccountingLine : sourceAccountingLines) {
        KualiDecimal lineAmount = sourceAccountingLine.getAmount();
        PaymentAccountDetail paymentAccountDetail = new PaymentAccountDetail();
        paymentAccountDetail.setAccountNbr(sourceAccountingLine.getAccountNumber());

        if (creditMemoDocType.equals(documentType)) {
            lineAmount = lineAmount.negated();
        }
        paymentAccountDetail.setAccountNetAmount(lineAmount);
        paymentAccountDetail.setFinChartCode(sourceAccountingLine.getChartOfAccountsCode());
        paymentAccountDetail.setFinObjectCode(sourceAccountingLine.getFinancialObjectCode());

        paymentAccountDetail.setFinSubObjectCode(
                StringUtils.defaultIfEmpty(sourceAccountingLine.getFinancialSubObjectCode(),
                        KFSConstants.getDashFinancialSubObjectCode()));
        paymentAccountDetail.setOrgReferenceId(sourceAccountingLine.getOrganizationReferenceId());
        paymentAccountDetail.setProjectCode(StringUtils.defaultIfEmpty(sourceAccountingLine.getProjectCode(),
                KFSConstants.getDashProjectCode()));
        paymentAccountDetail.setSubAccountNbr(StringUtils.defaultIfEmpty(
                sourceAccountingLine.getSubAccountNumber(), KFSConstants.getDashSubAccountNumber()));
        paymentDetail.addAccountDetail(paymentAccountDetail);
    }
}

From source file:org.kuali.kfs.module.tem.batch.service.impl.ImportedExpensePendingEntryServiceImpl.java

/**
 * @see org.kuali.kfs.module.tem.batch.service.ImportedExpensePendingEntryService#buildGeneralLedgerPendingEntry(org.kuali.kfs.module.tem.businessobject.AgencyStagingData, org.kuali.kfs.module.tem.businessobject.TripAccountingInformation, org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper, java.lang.String, java.lang.String, org.kuali.rice.kns.util.KualiDecimal, java.lang.String)
 *//* w  ww  . j a va2 s .c om*/
@Override
public GeneralLedgerPendingEntry buildGeneralLedgerPendingEntry(AgencyStagingData agencyData,
        TripAccountingInformation info, GeneralLedgerPendingEntrySequenceHelper sequenceHelper,
        String chartCode, String objectCode, KualiDecimal amount, String glCredtiDebitCode) {

    ObjectCode objectCd = getObjectCodeService().getByPrimaryIdForCurrentYear(chartCode, objectCode);
    if (ObjectUtils.isNull(objectCd)) {
        LOG.error("ERROR: Could not get an ObjectCode for chart code: " + chartCode + " object code: "
                + objectCode);
        return null;
    }

    GeneralLedgerPendingEntry glpe = buildBasicDistributionPendingEntry(sequenceHelper);
    //setup document number by agency data
    glpe.setDocumentNumber(getImportExpenseDocumentNumber(agencyData));
    // customizations for glpe
    glpe.setChartOfAccountsCode(chartCode);
    glpe.setFinancialObjectCode(objectCode);
    glpe.setFinancialSubObjectCode(StringUtils.defaultIfEmpty(info.getSubObjectCode(),
            GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialSubObjectCode()));
    glpe.setFinancialObjectTypeCode(objectCd.getFinancialObjectTypeCode());
    glpe.setProjectCode(StringUtils.defaultIfEmpty(info.getProjectCode(),
            GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankProjectCode()));
    glpe.setTransactionLedgerEntryAmount(amount);
    glpe.setTransactionDebitCreditCode(glCredtiDebitCode);
    glpe.setTransactionDate(agencyData.getTransactionPostingDate());
    glpe.setOrganizationDocumentNumber(
            StringUtils.isNotEmpty(agencyData.getTravelerId()) ? agencyData.getTravelerId()
                    : agencyData.getTripId());
    glpe.setFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.APPROVED);

    return glpe;
}

From source file:org.kuali.kfs.module.tem.batch.service.impl.ImportedExpensePendingEntryServiceImpl.java

/**
 * @see org.kuali.kfs.module.tem.batch.service.ImportedExpensePendingEntryService#buildDebitPendingEntry(org.kuali.kfs.module.tem.businessobject.AgencyStagingData, org.kuali.kfs.module.tem.businessobject.TripAccountingInformation, org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper, java.lang.String, org.kuali.rice.kns.util.KualiDecimal, boolean)
 *//* www. jav  a 2  s  .  c om*/
@Override
public List<GeneralLedgerPendingEntry> buildDebitPendingEntry(AgencyStagingData agencyData,
        TripAccountingInformation info, GeneralLedgerPendingEntrySequenceHelper sequenceHelper,
        String objectCode, KualiDecimal amount, boolean generateOffset) {

    List<GeneralLedgerPendingEntry> entryList = new ArrayList<GeneralLedgerPendingEntry>();

    GeneralLedgerPendingEntry pendingEntry = buildGeneralLedgerPendingEntry(agencyData, info, sequenceHelper,
            info.getTripChartCode(), objectCode, amount, KFSConstants.GL_DEBIT_CODE);
    if (ObjectUtils.isNotNull(pendingEntry)) {
        pendingEntry.setAccountNumber(info.getTripAccountNumber());
        pendingEntry.setSubAccountNumber(StringUtils.defaultIfEmpty(info.getTripSubAccountNumber(),
                GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankSubAccountNumber()));

        LOG.info("Created DEBIT GLPE: " + pendingEntry.getDocumentNumber() + " for AGENCY Import Expense: "
                + agencyData.getId() + " TripId: " + agencyData.getTripId() + "\n\n"
                + ReflectionToStringBuilder.reflectionToString(pendingEntry, ToStringStyle.MULTI_LINE_STYLE));

        //add to list if entry was created successfully
        entryList.add(pendingEntry);
        //handling offset
        if (generateOffset) {
            generateOffsetPendingEntry(entryList, sequenceHelper, pendingEntry);
        }
    }
    return entryList;
}

From source file:org.kuali.kfs.module.tem.batch.service.impl.TemProfileExportServiceImpl.java

protected Element generateProfileDetailElement(Document doc, TemProfile profile) {
    Element profileDetail = doc.createElement("profileDetail");

    profileDetail.appendChild(createElement(doc, "travelerProfileID", profile.getProfileId().toString()));
    profileDetail.appendChild(/*w  w w . j  a va 2  s  .co m*/
            createElement(doc, "travelerType", StringUtils.defaultIfEmpty(profile.getTravelerTypeCode(), "")));
    profileDetail.appendChild(
            createElement(doc, "travelerEmployeeID", StringUtils.defaultIfEmpty(profile.getEmployeeId(), "")));
    profileDetail.appendChild(createElement(doc, "principalName", getPrincipalName(profile.getPrincipalId())));
    profileDetail.appendChild(
            createElement(doc, "firstName", StringUtils.defaultIfEmpty(profile.getFirstName(), "")));
    profileDetail.appendChild(
            createElement(doc, "middleName", StringUtils.defaultIfEmpty(profile.getMiddleName(), "")));
    profileDetail
            .appendChild(createElement(doc, "lastName", StringUtils.defaultIfEmpty(profile.getLastName(), "")));
    profileDetail
            .appendChild(createElement(doc, "fullName", StringUtils.defaultIfEmpty(profile.getName(), "")));
    profileDetail.appendChild(createElement(doc, "dateOfBirth",
            ObjectUtils.isNotNull(profile.getDateOfBirth())
                    ? dateTimeService.toDateString(profile.getDateOfBirth())
                    : ""));
    profileDetail
            .appendChild(createElement(doc, "gender", StringUtils.defaultIfEmpty(profile.getGender(), "")));
    if (ObjectUtils.isNotNull(profile.getTemProfileAddress())) {
        profileDetail.appendChild(createElement(doc, "streetAddress1",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStreetAddressLine1(), "")));
        profileDetail.appendChild(createElement(doc, "streetAddress2",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStreetAddressLine2(), "")));
        profileDetail.appendChild(createElement(doc, "city",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getCityName(), "")));
        profileDetail.appendChild(createElement(doc, "state",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStateCode(), "")));
        profileDetail.appendChild(createElement(doc, "zipCode",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getZipCode(), "")));
        profileDetail.appendChild(createElement(doc, "country",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getCountryCode(), "")));
    } else {
        //No address for this profile
        profileDetail.appendChild(createElement(doc, "streetAddress1", ""));
        profileDetail.appendChild(createElement(doc, "streetAddress2", ""));
        profileDetail.appendChild(createElement(doc, "city", ""));
        profileDetail.appendChild(createElement(doc, "state", ""));
        profileDetail.appendChild(createElement(doc, "zipCode", ""));
        profileDetail.appendChild(createElement(doc, "country", ""));
    }
    profileDetail.appendChild(
            createElement(doc, "phoneNumber", StringUtils.defaultIfEmpty(profile.getPhoneNumber(), "")));
    profileDetail.appendChild(
            createElement(doc, "emailAddress", StringUtils.defaultIfEmpty(profile.getEmailAddress(), "")));
    profileDetail.appendChild(createElement(doc, "primaryDepartment",
            StringUtils.defaultIfEmpty(profile.getHomeDepartment(), "")));

    return profileDetail;
}

From source file:org.kuali.kfs.module.tem.batch.service.impl.TemProfileExportServiceImpl.java

protected String generateCSVEntry(TemProfile profile) {
    StringBuffer line = new StringBuffer();

    line.append(profile.getProfileId().toString()).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getTravelerTypeCode(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getEmployeeId(), "")).append(",");
    line.append(getPrincipalName(profile.getPrincipalId())).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getFirstName(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getMiddleName(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getLastName(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getName(), "")).append(",");
    line.append(ObjectUtils.isNotNull(profile.getDateOfBirth())
            ? dateTimeService.toDateString(profile.getDateOfBirth())
            : "").append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getGender(), "")).append(",");
    if (ObjectUtils.isNotNull(profile.getTemProfileAddress())) {
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStreetAddressLine1(), ""))
                .append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStreetAddressLine2(), ""))
                .append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getCityName(), "")).append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStateCode(), "")).append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getZipCode(), "")).append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getCountryCode(), ""))
                .append(",");
    } else {/*from ww w.j a  v a2 s  .  co  m*/
        //No address for this profile
        line.append("").append(",");
        line.append("").append(",");
        line.append("").append(",");
        line.append("").append(",");
        line.append("").append(",");
        line.append("").append(",");
    }
    line.append(StringUtils.defaultIfEmpty(profile.getPhoneNumber(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getEmailAddress(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getHomeDepartment(), ""));

    return line.toString();
}

From source file:org.kuali.kfs.module.tem.batch.TemProfileExportStep.java

private Element generateProfileDetailElement(Document doc, TemProfile profile) {
    Element profileDetail = doc.createElement("profileDetail");

    profileDetail.appendChild(createElement(doc, "travelerProfileID", profile.getProfileId().toString()));
    profileDetail.appendChild(//from w  w  w.  j  a va  2  s  . c o  m
            createElement(doc, "travelerType", StringUtils.defaultIfEmpty(profile.getTravelerTypeCode(), "")));
    profileDetail.appendChild(
            createElement(doc, "travelerEmployeeID", StringUtils.defaultIfEmpty(profile.getEmployeeId(), "")));
    profileDetail.appendChild(createElement(doc, "principalName", getPrincipalName(profile.getPrincipalId())));
    profileDetail.appendChild(
            createElement(doc, "firstName", StringUtils.defaultIfEmpty(profile.getFirstName(), "")));
    profileDetail.appendChild(
            createElement(doc, "middleName", StringUtils.defaultIfEmpty(profile.getMiddleName(), "")));
    profileDetail
            .appendChild(createElement(doc, "lastName", StringUtils.defaultIfEmpty(profile.getLastName(), "")));
    profileDetail
            .appendChild(createElement(doc, "fullName", StringUtils.defaultIfEmpty(profile.getName(), "")));
    profileDetail.appendChild(createElement(doc, "dateOfBirth",
            ObjectUtils.isNotNull(profile.getDateOfBirth())
                    ? getDateTimeService().toDateString(profile.getDateOfBirth())
                    : ""));
    profileDetail
            .appendChild(createElement(doc, "gender", StringUtils.defaultIfEmpty(profile.getGender(), "")));
    if (ObjectUtils.isNotNull(profile.getTemProfileAddress())) {
        profileDetail.appendChild(createElement(doc, "streetAddress1",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStreetAddressLine1(), "")));
        profileDetail.appendChild(createElement(doc, "streetAddress2",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStreetAddressLine2(), "")));
        profileDetail.appendChild(createElement(doc, "city",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getCityName(), "")));
        profileDetail.appendChild(createElement(doc, "state",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStateCode(), "")));
        profileDetail.appendChild(createElement(doc, "zipCode",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getZipCode(), "")));
        profileDetail.appendChild(createElement(doc, "country",
                StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getCountryCode(), "")));
    } else {
        //No address for this profile
        profileDetail.appendChild(createElement(doc, "streetAddress1", ""));
        profileDetail.appendChild(createElement(doc, "streetAddress2", ""));
        profileDetail.appendChild(createElement(doc, "city", ""));
        profileDetail.appendChild(createElement(doc, "state", ""));
        profileDetail.appendChild(createElement(doc, "zipCode", ""));
        profileDetail.appendChild(createElement(doc, "country", ""));
    }
    profileDetail.appendChild(
            createElement(doc, "phoneNumber", StringUtils.defaultIfEmpty(profile.getPhoneNumber(), "")));
    profileDetail.appendChild(
            createElement(doc, "emailAddress", StringUtils.defaultIfEmpty(profile.getEmailAddress(), "")));
    profileDetail.appendChild(createElement(doc, "primaryDepartment",
            StringUtils.defaultIfEmpty(profile.getHomeDepartment(), "")));

    return profileDetail;
}

From source file:org.kuali.kfs.module.tem.batch.TemProfileExportStep.java

private String generateCSVEntry(TemProfile profile) {
    StringBuffer line = new StringBuffer();

    line.append(profile.getProfileId().toString()).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getTravelerTypeCode(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getEmployeeId(), "")).append(",");
    line.append(getPrincipalName(profile.getPrincipalId())).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getFirstName(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getMiddleName(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getLastName(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getName(), "")).append(",");
    line.append(ObjectUtils.isNotNull(profile.getDateOfBirth())
            ? getDateTimeService().toDateString(profile.getDateOfBirth())
            : "").append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getGender(), "")).append(",");
    if (ObjectUtils.isNotNull(profile.getTemProfileAddress())) {
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStreetAddressLine1(), ""))
                .append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStreetAddressLine2(), ""))
                .append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getCityName(), "")).append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getStateCode(), "")).append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getZipCode(), "")).append(",");
        line.append(StringUtils.defaultIfEmpty(profile.getTemProfileAddress().getCountryCode(), ""))
                .append(",");
    } else {// w  ww . j a v a2s . c  o m
        //No address for this profile
        line.append("").append(",");
        line.append("").append(",");
        line.append("").append(",");
        line.append("").append(",");
        line.append("").append(",");
        line.append("").append(",");
    }
    line.append(StringUtils.defaultIfEmpty(profile.getPhoneNumber(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getEmailAddress(), "")).append(",");
    line.append(StringUtils.defaultIfEmpty(profile.getHomeDepartment(), ""));

    return line.toString();
}