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

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

Introduction

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

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

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

protected String getValue(String line, int s, int e) {
    //  String v = line.substring(s, e);
    return org.springframework.util.StringUtils.trimTrailingWhitespace(StringUtils.substring(line, s, e));
}

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/*w  ww  . j av a 2 s  .c  o  m*/
 */
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.ld.batch.service.LaborScrubberServiceTest.java

public void testBlankFiscalYear() throws Exception {
    String[] inputTransactions = {
            "    BA6044900-----2400---ACEX06BT  PLBLANKFISC     0000100009529----------KUALI TEST DESCRIPTION                  +00000000000003493.50D2008-12-22                                                 2008-12-222008-12-31000168.002009060000149952 001REGS12PAE 11 M001010207                     IU IUBLA" };

    String expectedOutput = this.testingYear + StringUtils.substring(inputTransactions[0], 4, 29)
            + this.testingPeriodCode + StringUtils.substring(inputTransactions[0], 31);
    EntryHolder[] outputTransactions = {
            new EntryHolder(LaborConstants.BatchFileSystem.SCRUBBER_INPUT_FILE, inputTransactions[0]),
            new EntryHolder(LaborConstants.BatchFileSystem.SCRUBBER_VALID_OUTPUT_FILE, expectedOutput) };

    scrub(inputTransactions);//from   w  ww  . j a v  a 2  s  .c  o m
    assertOriginEntries(4, outputTransactions);
}

From source file:org.kuali.kfs.module.tem.document.maintenance.AgencyStagingDataMaintainable.java

/**
*
* This method trims the descriptionText to 40 characters.
* @param descriptionText//from  w w w .j a v a 2 s . co  m
* @return
*/
protected String trimDescription(String descriptionText) {
    return StringUtils.substring(descriptionText, 0, 39);
}

From source file:org.kuali.kfs.sys.context.BatchStepFileDescriptor.java

/**
 * Retrieves the name of the job from the File
 *
 * @param runFile the semaphore file/*from   w  ww .  j  a  v  a 2s.  c o  m*/
 * @return the job name
 */
private String getJobNameFromFile(File runFile) {
    String runFileName = runFile.getName();
    int indexOfExtension = runFileName.lastIndexOf(STEP_FILE_EXTENSION_SEPARATOR);
    String fileNameNoExtension = StringUtils.substring(runFileName, 0, indexOfExtension);
    int indexOfStep = fileNameNoExtension.lastIndexOf(STEP_FILE_NAME_SEPARATOR);
    String jobName = StringUtils.substring(fileNameNoExtension, 0, indexOfStep);
    return jobName;
}

From source file:org.kuali.kfs.sys.context.BatchStepFileDescriptor.java

/**
 * Retrieves the name of the step from the File
 *
 * @param runFile the semaphore file/*  www  .  j a  va 2  s .  com*/
 * @return the step name
 */
private String getStepNameFromFile(File runFile) {
    String runFileName = runFile.getName();
    int indexOfExtension = runFileName.lastIndexOf(STEP_FILE_EXTENSION_SEPARATOR);
    String fileNameNoExtension = StringUtils.substring(runFileName, 0, indexOfExtension);
    int indexOfStep = fileNameNoExtension.lastIndexOf(STEP_FILE_NAME_SEPARATOR);
    String stepName = StringUtils.substring(fileNameNoExtension, indexOfStep + 1);
    return stepName;
}

From source file:org.kuali.kfs.sys.service.impl.ReportWriterTextServiceImpl.java

/**
 * @param printBusinessObjectValues indicates whether the bo values should be printed before the message
 * @see org.kuali.kfs.sys.service.ReportWriterService#writeError(java.lang.Class, org.kuali.kfs.sys.Message)
 *//* w w  w.j  ava  2s . c o  m*/
public void writeError(BusinessObject businessObject, Message message, boolean printBusinessObjectValues) {
    // Check if we need to write a new table header. We do this if it hasn't been written before or if the businessObject
    // changed
    if (newPage || businessObjectClass == null
            || !businessObjectClass.getName().equals(businessObject.getClass().getName())) {
        if (businessObjectClass == null) {
            // If we didn't write the header before, write it with a subTitle
            this.writeSubTitle(errorSubTitle);
        } else if (!businessObjectClass.getName().equals(businessObject.getClass().getName())) {
            // If it changed push a newline in for neater formatting
            this.writeNewLines(1);
        }

        this.writeErrorHeader(businessObject);
        newPage = false;
        businessObjectClass = businessObject.getClass();
    }

    // Get business object formatter that will be used
    BusinessObjectReportHelper businessObjectReportHelper = getBusinessObjectReportHelper(businessObject);

    // Print the values of the businessObject per formatting determined by writeErrorHeader
    List<Object> formatterArgs = new ArrayList<Object>();
    if (printBusinessObjectValues) {
        formatterArgs.addAll(businessObjectReportHelper.getValues(businessObject));
    } else {
        formatterArgs.addAll(businessObjectReportHelper.getBlankValues(businessObject));
    }

    // write rest of message on new line(s) if it was cut off
    int maxMessageLength = Integer
            .parseInt(StringUtils.substringBefore(StringUtils.substringAfterLast(errorFormat, "%-"), "s"));
    String messageToPrint = message.getMessage();

    boolean firstMessageLine = true;
    while (messageToPrint.length() > 0 && StringUtils.isNotBlank(messageToPrint)) {
        if (!firstMessageLine) {
            formatterArgs = new ArrayList<Object>();
            formatterArgs.addAll(businessObjectReportHelper.getBlankValues(businessObject));
        } else {
            firstMessageLine = false;
        }

        messageToPrint = StringUtils.trim(messageToPrint);
        String messageLine = messageToPrint;
        if (messageLine.length() > maxMessageLength) {
            messageLine = StringUtils.substring(messageLine, 0, maxMessageLength);
            if (StringUtils.contains(messageLine, " ")) {
                messageLine = StringUtils.substringBeforeLast(messageLine, " ");
            }
        }

        formatterArgs.add(new Message(messageLine, message.getType()));
        this.writeFormattedMessageLine(errorFormat, formatterArgs.toArray());

        messageToPrint = StringUtils.removeStart(messageToPrint, messageLine);
    }
}

From source file:org.kuali.kfs.vnd.batch.dataaccess.DebarredVendorDaoJdbc.java

/**
 * Gets the addressGeneratedId of the vendor address that matches best with the address of the
 * EPLS debarred vendor in the specified vendor exclude match.
 * If no address matches, returns the default address for IU campus.
 *///w  w  w .  j  a  v a2  s  .  c om
protected long getMatchAddressId(DebarredVendorMatch match) {
    long bestid = 0;
    long defaultId = 0;
    int maxPriority = 0;
    List<VendorAddress> addresses = vendorService.getVendorDetail(match.getVendorHeaderGeneratedIdentifier(),
            match.getVendorDetailAssignedIdentifier()).getVendorAddresses();
    if (addresses == null) {
        return bestid;
    }

    for (VendorAddress address : addresses) {
        if (address.isVendorDefaultAddressIndicator()) {
            defaultId = address.getVendorAddressGeneratedIdentifier();
        }
        //each condition satisfied will increase the priority score for this address
        int priority = 0;
        String vendorAddr1 = StringUtils.replaceChars(address.getVendorLine1Address(), ".,# ", "");
        String eplsAddr1 = StringUtils.replaceChars(match.getAddress1(), ".,# ", "");
        if (StringUtils.equalsIgnoreCase(vendorAddr1, eplsAddr1)) {
            priority++;
        }
        String vendorCity = StringUtils.replaceChars(address.getVendorCityName(), "., ", "");
        String eplsCity = StringUtils.replaceChars(match.getCity(), "., ", "");
        if (StringUtils.equalsIgnoreCase(vendorCity, eplsCity)) {
            priority++;
        }
        if (StringUtils.equalsIgnoreCase(address.getVendorStateCode(), match.getState())) {
            priority++;
        }
        String vendorZip = StringUtils.substring(address.getVendorZipCode(), 0, 5);
        String eplsZip = StringUtils.substring(match.getZip(), 0, 5);
        if (StringUtils.equals(vendorZip, eplsZip)) {
            priority++;
        }
        if (priority >= maxPriority) {
            bestid = address.getVendorAddressGeneratedIdentifier();
            maxPriority = priority;
        }
    }
    if (bestid == 0) {
        bestid = defaultId;
    }
    return bestid;
}

From source file:org.kuali.kra.bo.KraPersistableBusinessObjectBase.java

/**
 * Sets the update user, making sure it is not the system user and truncating the name so it will fit.
 *
 * @param updateUser the user who updated this object
 *//*from ww w.  ja  v a 2  s  . c  om*/
public void setUpdateUser(String updateUser) {
    if (!KNSConstants.SYSTEM_USER.equals(updateUser)) {
        this.updateUser = StringUtils.substring(updateUser, 0, UPDATE_USER_LENGTH);
    }
}

From source file:org.kuali.rice.kim.impl.identity.PersonServiceImpl.java

private boolean isPersonProperty(Object bo, String propertyName) {
    try {/*ww w.ja  v  a  2s  . c  om*/
        if (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName) // is a nested property
                && !StringUtils.contains(propertyName, "add.")) {// exclude add line properties (due to path parsing problems in PropertyUtils.getPropertyType)
            int lastIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(propertyName);
            String propertyTypeName = lastIndex != -1 ? StringUtils.substring(propertyName, 0, lastIndex)
                    : StringUtils.EMPTY;
            Class<?> type = PropertyUtils.getPropertyType(bo, propertyTypeName);
            // property type indicates a Person object
            if (type != null) {
                return Person.class.isAssignableFrom(type);
            }
            LOG.warn("Unable to determine type of nested property: " + bo.getClass().getName() + " / "
                    + propertyName);
        }
    } catch (Exception ex) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Unable to determine if property on " + bo.getClass().getName() + " to a person object: "
                    + propertyName, ex);
        }
    }
    return false;
}