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

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

Introduction

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

Prototype

public static String rightPad(String str, int size) 

Source Link

Document

Right pad a String with spaces (' ').

Usage

From source file:org.jumpmind.symmetric.util.SnapshotUtil.java

protected static void writeJobsStats(ISymmetricEngine engine, File tmpDir) {
    FileWriter writer = null;/*w  w w  .  j  av  a  2  s.  c o m*/
    try {
        writer = new FileWriter(new File(tmpDir, "jobs.txt"));
        IJobManager jobManager = engine.getJobManager();
        IClusterService clusterService = engine.getClusterService();
        INodeService nodeService = engine.getNodeService();
        writer.write("There are " + nodeService.findNodeHosts(nodeService.findIdentityNodeId()).size()
                + " instances in the cluster\n\n");
        writer.write(StringUtils.rightPad("Job Name", 30) + StringUtils.rightPad("Schedule", 20)
                + StringUtils.rightPad("Status", 10) + StringUtils.rightPad("Server Id", 30)
                + StringUtils.rightPad("Last Server Id", 30) + StringUtils.rightPad("Last Finish Time", 30)
                + StringUtils.rightPad("Last Run Period", 20) + StringUtils.rightPad("Avg. Run Period", 20)
                + "\n");
        List<IJob> jobs = jobManager.getJobs();
        Map<String, Lock> locks = clusterService.findLocks();
        for (IJob job : jobs) {
            Lock lock = locks.get(job.getClusterLockName());
            String status = getJobStatus(job, lock);
            String runningServerId = lock != null ? lock.getLockingServerId() : "";
            String lastServerId = clusterService.getServerId();
            if (lock != null) {
                lastServerId = lock.getLastLockingServerId();
            }
            String schedule = StringUtils.isBlank(job.getCronExpression())
                    ? Long.toString(job.getTimeBetweenRunsInMs())
                    : job.getCronExpression();
            String lastFinishTime = getLastFinishTime(job, lock);

            writer.write(StringUtils.rightPad(job.getClusterLockName().replace("_", " "), 30)
                    + StringUtils.rightPad(schedule, 20) + StringUtils.rightPad(status, 10)
                    + StringUtils.rightPad(runningServerId == null ? "" : runningServerId, 30)
                    + StringUtils.rightPad(lastServerId == null ? "" : lastServerId, 30)
                    + StringUtils.rightPad(lastFinishTime == null ? "" : lastFinishTime, 30)
                    + StringUtils.rightPad(job.getLastExecutionTimeInMs() + "", 20)
                    + StringUtils.rightPad(job.getAverageExecutionTimeInMs() + "", 20) + "\n");
        }
    } catch (IOException e) {
        log.warn("Failed to write jobs information", e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:org.jumpmind.vaadin.ui.sqlexplorer.SqlRunner.java

protected String resultsAsText(Statement stmt, int maxResultSize) throws SQLException {
    ResultSet rs = null;/*from   w  w  w  .  j  a va 2s.  c o  m*/
    try {
        rs = stmt.getResultSet();
        ResultSetMetaData meta = rs.getMetaData();
        int columns = meta.getColumnCount();
        int[] maxColumnSizes = new int[columns];
        for (int i = 1; i <= columns; i++) {
            String columnName = meta.getColumnName(i);
            maxColumnSizes[i - 1] = columnName.length();
        }
        int rowNumber = 1;
        List<Object[]> rows = new ArrayList<Object[]>();
        while (rs.next() && rowNumber <= maxResultSize) {
            Object[] row = new Object[columns];
            for (int i = 1; i <= columns; i++) {
                Object obj = CommonUiUtils.getObject(rs, i);
                row[i - 1] = obj;
                if (obj != null) {
                    int size = obj.toString().length();
                    if (maxColumnSizes[i - 1] < size) {
                        maxColumnSizes[i - 1] = size;
                    }
                }
            }
            rows.add(row);
            rowNumber++;
        }

        StringBuilder text = new StringBuilder();
        for (int i = 1; i <= columns; i++) {
            String columnName = meta.getColumnName(i);
            text.append(StringUtils.rightPad(columnName, maxColumnSizes[i - 1]));
            text.append(" ");
        }
        text.append("\n");

        for (int i = 1; i <= columns; i++) {
            text.append(StringUtils.rightPad("", maxColumnSizes[i - 1], "-"));
            text.append(" ");
        }
        text.append("\n");

        for (Object[] objects : rows) {
            for (int i = 0; i < objects.length; i++) {
                text.append(StringUtils.rightPad(objects[i] != null ? objects[i].toString() : "<null>",
                        maxColumnSizes[i]));
                text.append(" ");
            }
            text.append("\n");
        }

        return text.toString();
    } finally {
        JdbcSqlTemplate.close(rs);
    }
}

From source file:org.kuali.kfs.gl.dataaccess.impl.IcrEncumbranceDaoJdbc.java

/**
 * Retrieves and formats ICR Encumbrance information and writes output records to the file writer
 *
 * @param fiscalPeriod the current fiscal period
 * @param icrEncumbOriginCode the ICR origin code - system parameter INDIRECT_COST_RECOVERY_ENCUMBRANCE_ORIGINATION
 * @param icrEncumbBalanceTypes a list of balance types - system parameter INDIRECT_COST_RECOVERY_ENCUMBRANCE_BALANCE_TYPES
 * @param expenseObjectTypes a list of expense object types
 * @param encArgs a list of query arguments
 * @param fw the file writer//from w  ww  . ja v a 2s. c om
 */
protected void executeEncumbranceSql(final String fiscalPeriod, final String icrEncumbOriginCode,
        final Collection<String> icrEncumbBalanceTypes, final String[] expenseObjectTypes, Object[] encArgs,
        final Writer fw) {
    final String encumbSql = "select t1.univ_fiscal_yr, t1.fin_coa_cd, t1.account_nbr, t1.sub_acct_nbr, t5.fin_object_cd, t1.fin_balance_typ_cd, "
            + "t1.fdoc_typ_cd, t1.fdoc_nbr, " + "sum("
            + getDbPlatform().getIsNullFunction("t1.acln_encum_amt - t1.acln_encum_cls_amt", "0") + " * "
            + getDbPlatform().getIsNullFunction("t5.awrd_icr_rate_pct", "0") + " * .01) encumb_amt  "
            + "from gl_encumbrance_t t1 "
            + "join ca_icr_auto_entr_t t5 on t5.fin_series_id = ? and t5.univ_fiscal_yr = t1.univ_fiscal_yr "
            + "and t5.trn_debit_crdt_cd = 'D' "
            + "join ca_object_code_t t4 on t4.univ_fiscal_yr = t1.univ_fiscal_yr and t4.fin_coa_cd = t1.fin_coa_cd and t4.fin_object_cd = t1.fin_object_cd "
            + "where not exists (select 1 from ca_icr_excl_type_t where acct_icr_typ_cd = ? "
            + "and acct_icr_excl_typ_actv_ind = 'Y' and fin_object_cd = t1.fin_object_cd) "
            + "and t1.univ_fiscal_yr = ? and t1.fin_coa_cd = ? and t1.account_nbr = ? and t1.sub_acct_nbr = ? "
            + "and t1.fin_balance_typ_cd in (" + inString(icrEncumbBalanceTypes.size())
            + ") and t1.fs_origin_cd <> ? " + "and t4.fin_obj_typ_cd in (" + inString(expenseObjectTypes.length)
            + ") group by t1.univ_fiscal_yr, t1.fin_coa_cd, t1.account_nbr, t1.sub_acct_nbr, t5.fin_object_cd, t1.fin_balance_typ_cd, "
            + "t1.fdoc_typ_cd, t1.fdoc_nbr";

    getJdbcTemplate().query(encumbSql, encArgs, new ResultSetExtractor() {
        @Override
        public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
            try {
                String newLine = System.getProperty("line.separator");
                while (rs.next()) {
                    String fiscalYear = rs.getString("univ_fiscal_yr");
                    String chartCode = rs.getString("fin_coa_cd");
                    String accountNbr = rs.getString("account_nbr");
                    String subAccountNbr = rs.getString("sub_acct_nbr");
                    String objectCode = rs.getString("fin_object_cd");
                    String balanceType = rs.getString("fin_balance_typ_cd");
                    String docType = rs.getString("fdoc_typ_cd");
                    String docNbr = rs.getString("fdoc_nbr");

                    KualiDecimal encumb_amt = new KualiDecimal(rs.getDouble("encumb_amt"));
                    KualiDecimal current_amt = KualiDecimal.ZERO;

                    Object[] icrArgs = new String[9];
                    icrArgs[0] = fiscalYear;
                    icrArgs[1] = chartCode;
                    icrArgs[2] = accountNbr;
                    icrArgs[3] = subAccountNbr;
                    icrArgs[4] = objectCode;
                    icrArgs[5] = balanceType;
                    icrArgs[6] = docType;
                    icrArgs[7] = docNbr;
                    icrArgs[8] = icrEncumbOriginCode;

                    Double icrAmount = getCurrentEncumbranceAmount(icrArgs);

                    if (icrAmount != null) {
                        current_amt = new KualiDecimal(icrAmount);
                    }

                    KualiDecimal new_encumb_amt = encumb_amt.subtract(current_amt);
                    if (new_encumb_amt.isZero()) {
                        // ignore zero dollar amounts
                        continue;
                    }

                    icrArgs = new String[3];
                    icrArgs[0] = fiscalYear;
                    icrArgs[1] = chartCode;
                    icrArgs[2] = objectCode;

                    String objectTypeCode = getICRObjectTypeCode(icrArgs);

                    String desc = "ICR Encumbrance " + docType + " " + docNbr;
                    String debitCreditInd = "D";
                    if (new_encumb_amt.isNegative()) {
                        debitCreditInd = "C";
                    }

                    fw.write("" + fiscalYear // Fiscal year 1-4
                            + chartCode // Chart code 5-6
                            + accountNbr // Account Number 7-13
                            + StringUtils.rightPad(subAccountNbr, 5)// Sub Account 14-18
                            + objectCode // Object Code 19-22
                            + "---" // Sub Object 23-25
                            + balanceType // balance type code
                            + objectTypeCode // Object Type 28-29
                            + fiscalPeriod // Fiscal Period 30-31
                            + StringUtils.rightPad(docType, 4) // Document Type 32-35
                            + icrEncumbOriginCode // Origin Code 36-37
                            + StringUtils.rightPad(docNbr, 14) // Doc Number 38-51
                            + StringUtils.rightPad("", 5, '0') // Entry Seq Nbr 52-56
                            + StringUtils.rightPad(StringUtils.substring(desc, 0, 40), 40) // Description 57-96
                            + StringUtils.leftPad(new_encumb_amt.abs().toString(), 21, '0') // Amount 97-116
                            + debitCreditInd // Debit/Credit 117-117
                            + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) // Trans Date 118-127
                            + "          " // Org Doc Nbr 128-137
                            + "          " // Project Code 138-147
                            + "        " // orig ref id 148-155
                            + "    " // ref doc type 156-159
                            + "  " // ref origin code 160-161
                            + "              " // ref doc number 162-175
                            + "          " // reversal date 176-185
                            + "D" // Enc update code 186-186
                    );

                    fw.write(newLine);
                    fw.flush();
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } catch (DataAccessException ed) {
                throw new RuntimeException(ed);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }

            return null;
        }
    });
}

From source file:org.kuali.kfs.module.bc.document.service.impl.PayrateExportServiceImpl.java

/**
 * Returns a field that is the length of fieldSize, to facilitate formatting payrate export file
 * //from  ww w .  j av  a 2 s  .  c  o m
 * @param stringToPad
 * @param fieldSize
 * @return
 */
@NonTransactional
protected String padString(String stringToPad, int fieldSize, boolean leftJustifiy) {
    if (stringToPad.length() < fieldSize) {
        if (leftJustifiy)
            return StringUtils.rightPad(stringToPad, fieldSize);
        else
            return StringUtils.leftPad(stringToPad, fieldSize);
    } else if (stringToPad.length() > fieldSize)
        return stringToPad.substring(0, fieldSize - 1);

    return stringToPad;
}

From source file:org.kuali.kfs.pdp.service.impl.PdpEmailServiceImpl.java

/**
 * @see org.kuali.kfs.pdp.service.PdpEmailService#sendAchAdviceEmail(org.kuali.kfs.pdp.businessobject.PaymentGroup,
 *      org.kuali.kfs.pdp.businessobject.CustomerProfile, org.kuali.kfs.pdp.businessobject.PaymentDetail)
 *//*from  w  ww.ja  v  a 2 s  .  com*/
@Override
public void sendAchAdviceEmail(PaymentGroup paymentGroup, PaymentDetail paymentDetail,
        CustomerProfile customer) {
    LOG.debug("sendAchAdviceEmail() starting");

    MailMessage message = new MailMessage();
    String fromAddresses = customer.getAdviceReturnEmailAddr();
    String toAddresses = paymentGroup.getAdviceEmailAddress();
    Collection<String> ccAddresses = parameterService.getParameterValuesAsString(
            SendAchAdviceNotificationsStep.class,
            PdpParameterConstants.ACH_SUMMARY_CC_EMAIL_ADDRESSES_PARMAETER_NAME);
    Collection<String> bccAddresses = parameterService.getParameterValuesAsString(
            SendAchAdviceNotificationsStep.class,
            PdpParameterConstants.ACH_SUMMARY_BCC_EMAIL_ADDRESSES_PARMAETER_NAME);
    String batchAddresses = mailService.getBatchMailingList();
    String subject = customer.getAdviceSubjectLine();

    message.addToAddress(toAddresses);
    if (!ccAddresses.isEmpty()) {
        message.getCcAddresses().addAll(ccAddresses);
    }
    if (!bccAddresses.isEmpty()) {
        message.getBccAddresses().addAll(bccAddresses);
    }
    message.setFromAddress(fromAddresses);
    message.setSubject(subject);

    /* NOTE: The following code is unnecessary and counter-productive, because alterMessageWhenNonProductionInstance called below handles non-prd env
     * email to/cc addresses and subject properly, while Rice MailService handles adding app and env code in front of the subject line.
     * There's no need to add another layer to replace these addresses and subject. Replacing the real address with batchAddress will only result
     * in wiping out the original real addresses, which would have been added to the message body by MailService, for testing purpose.
    if (StringUtils.equals(productionEnvironmentCode, environmentCode)) {
    message.addToAddress(toAddresses);
    message.addCcAddress(ccAddresses);
    message.addBccAddress(ccAddresses);
    message.setFromAddress(fromAddresses);
    message.setSubject(subject);
    }
    else {
    message.addToAddress(batchAddresses);
    message.addCcAddress(batchAddresses);
    message.addBccAddress(batchAddresses);
    message.setFromAddress(fromAddresses);
    message.setSubject(environmentCode + ": " + subject + ":" + toAddresses);
    }
    */

    if (LOG.isDebugEnabled()) {
        LOG.debug("sending email to " + toAddresses + " for disb # " + paymentGroup.getDisbursementNbr());
    }

    StringBuilder body = new StringBuilder();
    body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_TOFROM, paymentGroup.getPayeeName(),
            customer.getAchPaymentDescription()));

    // formatter for payment amounts
    Formatter formatter = new CurrencyFormatter();

    // get bank name to which the payment is being transferred
    String bankName = "";

    ACHBank achBank = achBankService.getByPrimaryId(paymentGroup.getAchBankRoutingNbr());
    if (achBank == null) {
        LOG.error("Bank cound not be found for routing number " + paymentGroup.getAchBankRoutingNbr());
    } else {
        bankName = achBank.getBankName();
    }

    body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BANKAMOUNT, bankName,
            formatter.formatForPresentation(paymentDetail.getNetPaymentAmount())));

    // print detail amounts
    int labelPad = 25;

    String newPaymentAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
            PdpPropertyConstants.PaymentDetail.PAYMENT_NET_AMOUNT);
    body.append(StringUtils.rightPad(newPaymentAmountLabel, labelPad)
            + formatter.formatForPresentation(paymentDetail.getNetPaymentAmount()) + "\n");

    if (paymentDetail.getOrigInvoiceAmount().isNonZero()) {
        String origInvoiceAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_ORIGINAL_INVOICE_AMOUNT);
        body.append(StringUtils.rightPad(origInvoiceAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getOrigInvoiceAmount()) + "\n");
    }

    if (paymentDetail.getInvTotDiscountAmount().isNonZero()) {
        String invTotDiscountAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_TOTAL_DISCOUNT_AMOUNT);
        body.append(StringUtils.rightPad(invTotDiscountAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getInvTotDiscountAmount()) + "\n");
    }

    if (paymentDetail.getInvTotShipAmount().isNonZero()) {
        String invTotShippingAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_TOTAL_SHIPPING_AMOUNT);
        body.append(StringUtils.rightPad(invTotShippingAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getInvTotShipAmount()) + "\n");
    }

    if (paymentDetail.getInvTotOtherDebitAmount().isNonZero()) {
        String invTotOtherDebitAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_TOTAL_OTHER_DEBIT_AMOUNT);
        body.append(StringUtils.rightPad(invTotOtherDebitAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getInvTotOtherDebitAmount()) + "\n");
    }

    if (paymentDetail.getInvTotOtherCreditAmount().isNonZero()) {
        String invTotOtherCreditAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_TOTAL_OTHER_CREDIT_AMOUNT);
        body.append(StringUtils.rightPad(invTotOtherCreditAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getInvTotOtherCreditAmount()) + "\n");
    }

    body.append("\n" + customer.getAdviceHeaderText() + "\n");

    if (StringUtils.isNotBlank(paymentDetail.getPurchaseOrderNbr())) {
        String purchaseOrderNbrLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_PURCHASE_ORDER_NUMBER);
        body.append(StringUtils.rightPad(purchaseOrderNbrLabel, labelPad) + paymentDetail.getPurchaseOrderNbr()
                + "\n");
    }

    if (StringUtils.isNotBlank(paymentDetail.getInvoiceNbr())) {
        String invoiceNbrLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_NUMBER);
        body.append(StringUtils.rightPad(invoiceNbrLabel, labelPad) + paymentDetail.getInvoiceNbr() + "\n");
    }

    if (StringUtils.isNotBlank(paymentDetail.getCustPaymentDocNbr())) {
        String custPaymentDocNbrLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_CUSTOMER_DOC_NUMBER);
        body.append(StringUtils.rightPad(custPaymentDocNbrLabel, labelPad)
                + paymentDetail.getCustPaymentDocNbr() + "\n");
    }

    if (StringUtils.isNotBlank(paymentDetail.getCustomerInstitutionNumber())) {
        String customerInstituitionNbrLabel = dataDictionaryService.getAttributeLabel(PaymentGroup.class,
                PdpPropertyConstants.CUSTOMER_INSTITUTION_NUMBER);
        body.append(StringUtils.rightPad(customerInstituitionNbrLabel, labelPad)
                + paymentDetail.getCustomerInstitutionNumber() + "\n");
    }

    body.append("\n");

    // print payment notes
    for (PaymentNoteText paymentNoteText : paymentDetail.getNotes()) {
        body.append(paymentNoteText.getCustomerNoteText() + "\n");
    }

    if (paymentDetail.getNotes().isEmpty()) {
        body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_NONOTES));
    }

    message.setMessage(body.toString());

    // KFSMI-6475 - if not a production instance, replace the recipients with the testers list
    alterMessageWhenNonProductionInstance(message, null);

    try {
        mailService.sendMessage(message);
    } catch (Exception e) {
        LOG.error("sendAchAdviceEmail() Invalid email address. Sending message to "
                + customer.getAdviceReturnEmailAddr(), e);

        // send notification to advice return address with payment details- need a new MailMessage here of course
        MailMessage msg = new MailMessage();
        msg.addToAddress(customer.getAdviceReturnEmailAddr());

        String returnAddress = parameterService.getParameterValueAsString(KFSConstants.ParameterNamespaces.PDP,
                "Batch", KFSConstants.FROM_EMAIL_ADDRESS_PARM_NM);
        if (StringUtils.isEmpty(returnAddress)) {
            returnAddress = mailService.getBatchMailingList();
        }
        msg.setFromAddress(returnAddress);
        msg.setSubject(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_INVALID_EMAIL_ADDRESS));

        LOG.warn("bouncing email to " + customer.getAdviceReturnEmailAddr() + " for disb # "
                + paymentGroup.getDisbursementNbr());
        // KFSMI-6475 - if not a production instance, replace the recipients with the testers list
        alterMessageWhenNonProductionInstance(msg, null);

        try {
            mailService.sendMessage(msg);
        } catch (Exception e1) {
            LOG.error("Could not send email to advice return email address on customer profile: "
                    + customer.getAdviceReturnEmailAddr(), e1);
            throw new RuntimeException(
                    "Could not send email to advice return email address on customer profile: "
                            + customer.getAdviceReturnEmailAddr());
        }
    }
}

From source file:org.kuali.kfs.pdp.service.impl.PendingTransactionServiceImpl.java

/**
 * Populates and stores a new GLPE for each account detail in the payment group.
 *
 * @param paymentGroup payment group to generate entries for
 * @param achFdocTypeCode doc type for ach disbursements
 * @param checkFdocTypeCod doc type for check disbursements
 * @param reversal boolean indicating if this is a reversal
 *///from  www . ja  v a  2s . c o  m
protected void populatePaymentGeneralLedgerPendingEntry(PaymentGroup paymentGroup, String achFdocTypeCode,
        String checkFdocTypeCod, boolean reversal) {
    List<PaymentAccountDetail> accountListings = new ArrayList<PaymentAccountDetail>();
    for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
        accountListings.addAll(paymentDetail.getAccountDetail());
    }

    GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper();
    for (PaymentAccountDetail paymentAccountDetail : accountListings) {
        GlPendingTransaction glPendingTransaction = new GlPendingTransaction();
        glPendingTransaction.setSequenceNbr(new KualiInteger(sequenceHelper.getSequenceCounter()));

        if (StringUtils.isNotBlank(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode())
                && StringUtils
                        .isNotBlank(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode())) {
            glPendingTransaction
                    .setFdocRefTypCd(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode());
            glPendingTransaction
                    .setFsRefOriginCd(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode());
        } else {
            glPendingTransaction.setFdocRefTypCd(PdpConstants.PDP_FDOC_TYPE_CODE);
            glPendingTransaction.setFsRefOriginCd(PdpConstants.PDP_FDOC_ORIGIN_CODE);
        }

        glPendingTransaction.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);

        Date transactionTimestamp = new Date(dateTimeService.getCurrentDate().getTime());
        glPendingTransaction.setTransactionDt(transactionTimestamp);
        AccountingPeriod fiscalPeriod = accountingPeriodService
                .getByDate(new java.sql.Date(transactionTimestamp.getTime()));
        glPendingTransaction.setUniversityFiscalYear(fiscalPeriod.getUniversityFiscalYear());
        glPendingTransaction.setUnivFiscalPrdCd(fiscalPeriod.getUniversityFiscalPeriodCode());

        glPendingTransaction.setAccountNumber(paymentAccountDetail.getAccountNbr());
        glPendingTransaction.setSubAccountNumber(paymentAccountDetail.getSubAccountNbr());
        glPendingTransaction.setChartOfAccountsCode(paymentAccountDetail.getFinChartCode());

        if (paymentGroup.getDisbursementType().getCode().equals(PdpConstants.DisbursementTypeCodes.ACH)) {
            glPendingTransaction.setFinancialDocumentTypeCode(achFdocTypeCode);
        } else if (paymentGroup.getDisbursementType().getCode()
                .equals(PdpConstants.DisbursementTypeCodes.CHECK)) {
            glPendingTransaction.setFinancialDocumentTypeCode(checkFdocTypeCod);
        }

        glPendingTransaction.setFsOriginCd(PdpConstants.PDP_FDOC_ORIGIN_CODE);
        glPendingTransaction.setFdocNbr(paymentGroup.getDisbursementNbr().toString());

        Boolean relieveLiabilities = paymentGroup.getBatch().getCustomerProfile().getRelieveLiabilities();
        if ((relieveLiabilities != null) && (relieveLiabilities.booleanValue())
                && paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode() != null) {
            OffsetDefinition offsetDefinition = SpringContext.getBean(OffsetDefinitionService.class)
                    .getByPrimaryId(glPendingTransaction.getUniversityFiscalYear(),
                            glPendingTransaction.getChartOfAccountsCode(),
                            paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode(),
                            glPendingTransaction.getFinancialBalanceTypeCode());
            glPendingTransaction
                    .setFinancialObjectCode(offsetDefinition != null ? offsetDefinition.getFinancialObjectCode()
                            : paymentAccountDetail.getFinObjectCode());
            glPendingTransaction.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
        } else {
            glPendingTransaction.setFinancialObjectCode(paymentAccountDetail.getFinObjectCode());
            glPendingTransaction.setFinancialSubObjectCode(paymentAccountDetail.getFinSubObjectCode());
        }

        glPendingTransaction.setProjectCd(paymentAccountDetail.getProjectCode());
        glPendingTransaction.setDebitCrdtCd(
                pdpUtilService.isDebit(paymentAccountDetail, reversal) ? KFSConstants.GL_DEBIT_CODE
                        : KFSConstants.GL_CREDIT_CODE);
        glPendingTransaction.setAmount(paymentAccountDetail.getAccountNetAmount().abs());

        //Changes for Research Participant Upload
        String trnDesc = StringUtils.EMPTY;
        CustomerProfile customerProfile = paymentGroup.getBatch().getCustomerProfile();

        if (researchParticipantPaymentValidationService.isResearchParticipantPayment(customerProfile)) {
            BusinessObjectEntry businessObjectEntry = dataDictionaryService.getDataDictionary()
                    .getBusinessObjectEntry(PaymentDetail.class.getName());
            AttributeDefinition attributeDefinition = businessObjectEntry
                    .getAttributeDefinition("paymentGroup.payeeName");
            AttributeSecurity originalPayeeNameAttributeSecurity = attributeDefinition.getAttributeSecurity();
            //This is a temporary work around for an issue introduced with KFSCNTRB-705.
            if (ObjectUtils.isNotNull(originalPayeeNameAttributeSecurity)) {
                String maskLiteral = ((MaskFormatterLiteral) originalPayeeNameAttributeSecurity
                        .getMaskFormatter()).getLiteral();
                trnDesc = maskLiteral;
            }
        } else {
            String payeeName = paymentGroup.getPayeeName();
            if (StringUtils.isNotBlank(payeeName)) {
                trnDesc = payeeName.length() > 40 ? payeeName.substring(0, 40)
                        : StringUtils.rightPad(payeeName, 40);
            }

            if (reversal) {
                String poNbr = paymentAccountDetail.getPaymentDetail().getPurchaseOrderNbr();
                if (StringUtils.isNotBlank(poNbr)) {
                    trnDesc += " "
                            + (poNbr.length() > 9 ? poNbr.substring(0, 9) : StringUtils.rightPad(poNbr, 9));
                }

                String invoiceNbr = paymentAccountDetail.getPaymentDetail().getInvoiceNbr();
                if (StringUtils.isNotBlank(invoiceNbr)) {
                    trnDesc += " " + (invoiceNbr.length() > 14 ? invoiceNbr.substring(0, 14)
                            : StringUtils.rightPad(invoiceNbr, 14));
                }

                if (trnDesc.length() > 40) {
                    trnDesc = trnDesc.substring(0, 40);
                }
            }
        }
        glPendingTransaction.setDescription(trnDesc);

        glPendingTransaction.setOrgDocNbr(paymentAccountDetail.getPaymentDetail().getOrganizationDocNbr());
        glPendingTransaction.setOrgReferenceId(paymentAccountDetail.getOrgReferenceId());
        glPendingTransaction.setFdocRefNbr(paymentAccountDetail.getPaymentDetail().getCustPaymentDocNbr());

        // update the offset account if necessary
        SpringContext.getBean(FlexibleOffsetAccountService.class).updateOffset(glPendingTransaction);

        this.businessObjectService.save(glPendingTransaction);

        sequenceHelper.increment();

        if (bankService.isBankSpecificationEnabled()) {
            this.populateBankOffsetEntry(paymentGroup, glPendingTransaction, sequenceHelper);
        }
    }
}

From source file:org.kuali.ole.pdp.service.impl.PdpEmailServiceImpl.java

/**
 * @see org.kuali.ole.pdp.service.PdpEmailService#sendAchAdviceEmail(org.kuali.ole.pdp.businessobject.PaymentGroup,
 *      org.kuali.ole.pdp.businessobject.CustomerProfile, org.kuali.ole.pdp.businessobject.PaymentDetail)
 *///  ww  w . j a va2  s .co m
@Override
public void sendAchAdviceEmail(PaymentGroup paymentGroup, PaymentDetail paymentDetail,
        CustomerProfile customer) {
    LOG.debug("sendAchAdviceEmail() starting");

    MailMessage message = new MailMessage();
    //String productionEnvironmentCode = kualiConfigurationService.getPropertyValueAsString(OLEConstants.PROD_ENVIRONMENT_CODE_KEY);
    //String environmentCode = kualiConfigurationService.getPropertyValueAsString(OLEConstants.ENVIRONMENT_KEY);
    String fromAddresses = customer.getAdviceReturnEmailAddr();
    String toAddresses = paymentGroup.getAdviceEmailAddress();
    Collection<String> ccAddresses = parameterService.getParameterValuesAsString(
            SendAchAdviceNotificationsStep.class,
            PdpParameterConstants.ACH_SUMMARY_CC_EMAIL_ADDRESSES_PARMAETER_NAME);
    String batchAddresses = mailService.getBatchMailingList();
    String subject = customer.getAdviceSubjectLine();

    message.addToAddress(toAddresses);
    message.getCcAddresses().addAll(ccAddresses);
    //message.addBccAddress(ccAddresses);
    message.setFromAddress(fromAddresses);
    message.setSubject(subject);

    /* NOTE: The following code is unnecessary and counter-productive, because alterMessageWhenNonProductionInstance called below handles non-prd env 
     * email to/cc addresses and subject properly, while Rice MailService handles adding app and env code in front of the subject line.
     * There's no need to add another layer to replace these addresses and subject. Replacing the real address with batchAddress will only result
     * in wiping out the original real addresses, which would have been added to the message body by MailService, for testing purpose.         
    if (StringUtils.equals(productionEnvironmentCode, environmentCode)) {
    message.addToAddress(toAddresses);
    message.addCcAddress(ccAddresses);
    message.addBccAddress(ccAddresses);
    message.setFromAddress(fromAddresses);
    message.setSubject(subject);
    }
    else {
    message.addToAddress(batchAddresses);
    message.addCcAddress(batchAddresses);
    message.addBccAddress(batchAddresses);
    message.setFromAddress(fromAddresses);
    message.setSubject(environmentCode + ": " + subject + ":" + toAddresses);            
    }
    */

    if (LOG.isDebugEnabled()) {
        LOG.debug("sending email to " + toAddresses + " for disb # " + paymentGroup.getDisbursementNbr());
    }

    StringBuilder body = new StringBuilder();
    body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_TOFROM, paymentGroup.getPayeeName(),
            customer.getAchPaymentDescription()));

    // formatter for payment amounts
    Formatter formatter = new CurrencyFormatter();

    // get bank name to which the payment is being transferred
    String bankName = "";

    ACHBank achBank = achBankService.getByPrimaryId(paymentGroup.getAchBankRoutingNbr());
    if (achBank == null) {
        LOG.error("Bank cound not be found for routing number " + paymentGroup.getAchBankRoutingNbr());
    } else {
        bankName = achBank.getBankName();
    }

    body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_BANKAMOUNT, bankName,
            formatter.formatForPresentation(paymentDetail.getNetPaymentAmount())));

    // print detail amounts
    int labelPad = 25;

    String newPaymentAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
            PdpPropertyConstants.PaymentDetail.PAYMENT_NET_AMOUNT);
    body.append(StringUtils.rightPad(newPaymentAmountLabel, labelPad)
            + formatter.formatForPresentation(paymentDetail.getNetPaymentAmount()) + "\n");

    if (paymentDetail.getOrigInvoiceAmount().isNonZero()) {
        String origInvoiceAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_ORIGINAL_INVOICE_AMOUNT);
        body.append(StringUtils.rightPad(origInvoiceAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getOrigInvoiceAmount()) + "\n");
    }

    if (paymentDetail.getInvTotDiscountAmount().isNonZero()) {
        String invTotDiscountAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_TOTAL_DISCOUNT_AMOUNT);
        body.append(StringUtils.rightPad(invTotDiscountAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getInvTotDiscountAmount()) + "\n");
    }

    if (paymentDetail.getInvTotShipAmount().isNonZero()) {
        String invTotShippingAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_TOTAL_SHIPPING_AMOUNT);
        body.append(StringUtils.rightPad(invTotShippingAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getInvTotShipAmount()) + "\n");
    }

    if (paymentDetail.getInvTotOtherDebitAmount().isNonZero()) {
        String invTotOtherDebitAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_TOTAL_OTHER_DEBIT_AMOUNT);
        body.append(StringUtils.rightPad(invTotOtherDebitAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getInvTotOtherDebitAmount()) + "\n");
    }

    if (paymentDetail.getInvTotOtherCreditAmount().isNonZero()) {
        String invTotOtherCreditAmountLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_TOTAL_OTHER_CREDIT_AMOUNT);
        body.append(StringUtils.rightPad(invTotOtherCreditAmountLabel, labelPad)
                + formatter.formatForPresentation(paymentDetail.getInvTotOtherCreditAmount()) + "\n");
    }

    body.append("\n" + customer.getAdviceHeaderText() + "\n");

    if (StringUtils.isNotBlank(paymentDetail.getPurchaseOrderNbr())) {
        String purchaseOrderNbrLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_PURCHASE_ORDER_NUMBER);
        body.append(StringUtils.rightPad(purchaseOrderNbrLabel, labelPad) + paymentDetail.getPurchaseOrderNbr()
                + "\n");
    }

    if (StringUtils.isNotBlank(paymentDetail.getInvoiceNbr())) {
        String invoiceNbrLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_INVOICE_NUMBER);
        body.append(StringUtils.rightPad(invoiceNbrLabel, labelPad) + paymentDetail.getInvoiceNbr() + "\n");
    }

    if (StringUtils.isNotBlank(paymentDetail.getCustPaymentDocNbr())) {
        String custPaymentDocNbrLabel = dataDictionaryService.getAttributeLabel(PaymentDetail.class,
                PdpPropertyConstants.PaymentDetail.PAYMENT_CUSTOMER_DOC_NUMBER);
        body.append(StringUtils.rightPad(custPaymentDocNbrLabel, labelPad)
                + paymentDetail.getCustPaymentDocNbr() + "\n");
    }

    if (StringUtils.isNotBlank(paymentDetail.getCustomerInstitutionNumber())) {
        String customerInstituitionNbrLabel = dataDictionaryService.getAttributeLabel(PaymentGroup.class,
                PdpPropertyConstants.CUSTOMER_INSTITUTION_NUMBER);
        body.append(StringUtils.rightPad(customerInstituitionNbrLabel, labelPad)
                + paymentDetail.getCustomerInstitutionNumber() + "\n");
    }

    body.append("\n");

    // print payment notes
    for (PaymentNoteText paymentNoteText : paymentDetail.getNotes()) {
        body.append(paymentNoteText.getCustomerNoteText() + "\n");
    }

    if (paymentDetail.getNotes().isEmpty()) {
        body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_EMAIL_NONOTES));
    }

    message.setMessage(body.toString());

    // KFSMI-6475 - if not a production instance, replace the recipients with the testers list
    alterMessageWhenNonProductionInstance(message, null);

    try {
        mailService.sendMessage(message);
    } catch (Exception e) {
        LOG.error("sendAchAdviceEmail() Invalid email address. Sending message to "
                + customer.getAdviceReturnEmailAddr(), e);

        // send notification to advice return address with payment details
        message.addToAddress(customer.getAdviceReturnEmailAddr());

        String returnAddress = parameterService.getParameterValueAsString(OLEConstants.ParameterNamespaces.PDP,
                "Batch", OLEConstants.FROM_EMAIL_ADDRESS_PARM_NM);
        if (StringUtils.isEmpty(returnAddress)) {
            returnAddress = mailService.getBatchMailingList();
        }
        message.setFromAddress(returnAddress);
        message.setSubject(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_ADVICE_INVALID_EMAIL_ADDRESS));

        LOG.warn("bouncing email to " + customer.getAdviceReturnEmailAddr() + " for disb # "
                + paymentGroup.getDisbursementNbr());
        // KFSMI-6475 - if not a production instance, replace the recipients with the testers list
        alterMessageWhenNonProductionInstance(message, null);

        try {
            mailService.sendMessage(message);
        } catch (Exception e1) {
            LOG.error("Could not send email to advice return email address on customer profile: "
                    + customer.getAdviceReturnEmailAddr(), e1);
            throw new RuntimeException(
                    "Could not send email to advice return email address on customer profile: "
                            + customer.getAdviceReturnEmailAddr());
        }
    }
}

From source file:org.kuali.ole.pdp.service.impl.PendingTransactionServiceImpl.java

/**
 * Populates and stores a new GLPE for each account detail in the payment group.
 * /*from  w  ww  . j a  va2  s.c  o  m*/
 * @param paymentGroup payment group to generate entries for
 * @param achFdocTypeCode doc type for ach disbursements
 * @param checkFdocTypeCod doc type for check disbursements
 * @param reversal boolean indicating if this is a reversal
 */
protected void populatePaymentGeneralLedgerPendingEntry(PaymentGroup paymentGroup, String achFdocTypeCode,
        String checkFdocTypeCod, boolean reversal) {
    List<PaymentAccountDetail> accountListings = new ArrayList<PaymentAccountDetail>();
    for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
        accountListings.addAll(paymentDetail.getAccountDetail());
    }

    GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper();
    for (PaymentAccountDetail paymentAccountDetail : accountListings) {
        GlPendingTransaction glPendingTransaction = new GlPendingTransaction();
        glPendingTransaction.setSequenceNbr(new KualiInteger(sequenceHelper.getSequenceCounter()));

        if (StringUtils.isNotBlank(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode())
                && StringUtils
                        .isNotBlank(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode())) {
            glPendingTransaction
                    .setFdocRefTypCd(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode());
            glPendingTransaction
                    .setFsRefOriginCd(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode());
        } else {
            glPendingTransaction.setFdocRefTypCd(PdpConstants.PDP_FDOC_TYPE_CODE);
            glPendingTransaction.setFsRefOriginCd(PdpConstants.PDP_FDOC_ORIGIN_CODE);
        }

        glPendingTransaction.setFinancialBalanceTypeCode(OLEConstants.BALANCE_TYPE_ACTUAL);

        Date transactionTimestamp = new Date(dateTimeService.getCurrentDate().getTime());
        glPendingTransaction.setTransactionDt(transactionTimestamp);
        AccountingPeriod fiscalPeriod = accountingPeriodService
                .getByDate(new java.sql.Date(transactionTimestamp.getTime()));
        glPendingTransaction.setUniversityFiscalYear(fiscalPeriod.getUniversityFiscalYear());
        glPendingTransaction.setUnivFiscalPrdCd(fiscalPeriod.getUniversityFiscalPeriodCode());

        glPendingTransaction.setAccountNumber(paymentAccountDetail.getAccountNbr());
        glPendingTransaction.setSubAccountNumber(paymentAccountDetail.getSubAccountNbr());
        glPendingTransaction.setChartOfAccountsCode(paymentAccountDetail.getFinChartCode());

        if (paymentGroup.getDisbursementType().getCode().equals(PdpConstants.DisbursementTypeCodes.ACH)) {
            glPendingTransaction.setFinancialDocumentTypeCode(achFdocTypeCode);
        } else if (paymentGroup.getDisbursementType().getCode()
                .equals(PdpConstants.DisbursementTypeCodes.CHECK)) {
            glPendingTransaction.setFinancialDocumentTypeCode(checkFdocTypeCod);
        }

        glPendingTransaction.setFsOriginCd(PdpConstants.PDP_FDOC_ORIGIN_CODE);
        glPendingTransaction.setFdocNbr(paymentGroup.getDisbursementNbr().toString());

        Boolean relieveLiabilities = paymentGroup.getBatch().getCustomerProfile().getRelieveLiabilities();
        if ((relieveLiabilities != null) && (relieveLiabilities.booleanValue())
                && paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode() != null) {
            OffsetDefinition offsetDefinition = SpringContext.getBean(OffsetDefinitionService.class)
                    .getByPrimaryId(glPendingTransaction.getUniversityFiscalYear(),
                            glPendingTransaction.getChartOfAccountsCode(),
                            paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode(),
                            glPendingTransaction.getFinancialBalanceTypeCode());
            glPendingTransaction
                    .setFinancialObjectCode(offsetDefinition != null ? offsetDefinition.getFinancialObjectCode()
                            : paymentAccountDetail.getFinObjectCode());
            glPendingTransaction.setFinancialSubObjectCode(OLEConstants.getDashFinancialSubObjectCode());
        } else {
            glPendingTransaction.setFinancialObjectCode(paymentAccountDetail.getFinObjectCode());
            glPendingTransaction.setFinancialSubObjectCode(paymentAccountDetail.getFinSubObjectCode());
        }

        glPendingTransaction.setProjectCd(paymentAccountDetail.getProjectCode());
        if (paymentAccountDetail.getPaymentDetail().getNetPaymentAmount().bigDecimalValue().signum() >= 0) {
            glPendingTransaction
                    .setDebitCrdtCd(reversal ? OLEConstants.GL_CREDIT_CODE : OLEConstants.GL_DEBIT_CODE);
        } else {
            glPendingTransaction
                    .setDebitCrdtCd(reversal ? OLEConstants.GL_DEBIT_CODE : OLEConstants.GL_CREDIT_CODE);
        }
        glPendingTransaction.setAmount(paymentAccountDetail.getAccountNetAmount().abs());

        String trnDesc = "";

        String payeeName = paymentGroup.getPayeeName();
        if (StringUtils.isNotBlank(payeeName)) {
            trnDesc = payeeName.length() > 40 ? payeeName.substring(0, 40)
                    : StringUtils.rightPad(payeeName, 40);
        }

        if (reversal) {
            String poNbr = paymentAccountDetail.getPaymentDetail().getPurchaseOrderNbr();
            if (StringUtils.isNotBlank(poNbr)) {
                trnDesc += " " + (poNbr.length() > 9 ? poNbr.substring(0, 9) : StringUtils.rightPad(poNbr, 9));
            }

            String invoiceNbr = paymentAccountDetail.getPaymentDetail().getInvoiceNbr();
            if (StringUtils.isNotBlank(invoiceNbr)) {
                trnDesc += " " + (invoiceNbr.length() > 14 ? invoiceNbr.substring(0, 14)
                        : StringUtils.rightPad(invoiceNbr, 14));
            }

            if (trnDesc.length() > 40) {
                trnDesc = trnDesc.substring(0, 40);
            }
        }

        glPendingTransaction.setDescription(trnDesc);

        glPendingTransaction.setOrgDocNbr(paymentAccountDetail.getPaymentDetail().getOrganizationDocNbr());
        glPendingTransaction.setOrgReferenceId(paymentAccountDetail.getOrgReferenceId());
        glPendingTransaction.setFdocRefNbr(paymentAccountDetail.getPaymentDetail().getCustPaymentDocNbr());

        // update the offset account if necessary
        SpringContext.getBean(FlexibleOffsetAccountService.class).updateOffset(glPendingTransaction);

        this.businessObjectService.save(glPendingTransaction);

        sequenceHelper.increment();

        if (bankService.isBankSpecificationEnabled()) {
            this.populateBankOffsetEntry(paymentGroup, glPendingTransaction, sequenceHelper);
        }
    }
}

From source file:org.ofbiz.order.order.OrderServices.java

public static String nameTrim(String str, int n) {
    int strlen = str.length();
    if (strlen < n) {
        return StringUtils.rightPad(str, n);
    }// w ww.  j a  v  a 2s. c  o m
    if (strlen > n) {
        return str.substring(0, n);
    }
    return str;
}

From source file:org.openehr.adl.serializer.AdlStringBuilder.java

public AdlStringBuilder newline() {
    builder.append(StringUtils.rightPad("\n", indentDepth * 4 + 1));
    newLine = true;
    return this;
}