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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

From source file:org.kuali.kfs.gl.batch.service.impl.FileEnterpriseFeederServiceImpl.java

/**
 * Given the doneFile, this method finds the reconciliation file corresponding to the data file
 * //from  w  w w.j  a v a 2  s.  c o m
 * @param doneFile
 * @return a file for the reconciliation data, or null if the file doesn't exist or is not readable
 */
protected File getReconFile(File doneFile) {
    String doneFileAbsPath = doneFile.getAbsolutePath();
    if (!doneFileAbsPath.endsWith(DONE_FILE_SUFFIX)) {
        LOG.error("Done file name must end with " + DONE_FILE_SUFFIX);
        throw new IllegalArgumentException("DOne file name must end with " + DONE_FILE_SUFFIX);
    }
    String reconFileAbsPath = StringUtils.removeEnd(doneFileAbsPath, DONE_FILE_SUFFIX) + RECON_FILE_SUFFIX;
    File reconFile = new File(reconFileAbsPath);
    if (!reconFile.exists() || !reconFile.canRead()) {
        LOG.error("Cannot find/read data file " + reconFileAbsPath);
        return null;
    }
    return reconFile;
}

From source file:org.kuali.kfs.gl.batch.service.impl.ReconciliationParserServiceImpl.java

/**
 * Parses a reconciliation file// w ww  .  j  a  va 2 s  .  co m
 * 
 * @param reader a source of data from which to build a reconciliation
 * @param tableId defined within the reconciliation file; defines which block to parse
 * @return parsed reconciliation data
 * @throws IOException thrown if the file cannot be written for any reason
 * @see org.kuali.kfs.gl.batch.service.ReconciliationParserService#parseReconciliatioData(java.io.Reader)
 */
public ReconciliationBlock parseReconciliationBlock(Reader reader, String tableId) throws IOException {
    BufferedReader bufReader;
    if (reader instanceof BufferedReader) {
        bufReader = (BufferedReader) reader;
    } else {
        bufReader = new BufferedReader(reader);
    }

    // this variable is not null when we find the C line corresponding to the param table ID
    ReconciliationBlock reconciliationBlock = null;

    int linesInBlock = 0;

    // find the first "C" line of the C-E block by matching the table Id
    String line = bufReader.readLine();
    while (line != null && reconciliationBlock == null) {
        line = stripCommentsAndTrim(line);
        if (StringUtils.isBlank(line)) {
            line = bufReader.readLine();
            continue;
        }

        StringTokenizer strTok = new StringTokenizer(line);
        if (!strTok.hasMoreTokens()) {
            LOG.error("Cannot find TABLE_DEF_STRING");
            throw new RuntimeException();
        }
        String command = strTok.nextToken();
        if (command.equalsIgnoreCase(GeneralLedgerConstants.Reconciliation.TABLE_DEF_STRING)) {
            if (!strTok.hasMoreTokens()) {
                LOG.error("Cannot find TABLE_DEF_STRING");
                throw new RuntimeException();
            }
            String parsedTableId = strTok.nextToken();
            if (parsedTableId.equalsIgnoreCase(tableId)) {
                if (!strTok.hasMoreTokens()) {
                    LOG.error("Cannot find Parsed Table Id");
                    throw new RuntimeException();
                }
                String parsedRowCountStr = StringUtils.removeEnd(strTok.nextToken(), ";");
                parsedRowCountStr = StringUtils.removeEnd(parsedRowCountStr, ".00");
                int parsedRowCount = Integer.parseInt(parsedRowCountStr);

                reconciliationBlock = new ReconciliationBlock();
                reconciliationBlock.setTableId(parsedTableId);
                reconciliationBlock.setRowCount(parsedRowCount);

                linesInBlock++;

                break;
            }
        }
        line = bufReader.readLine();
    }

    if (reconciliationBlock == null) {
        return null;
    }

    boolean endBlockLineEncountered = false;
    line = bufReader.readLine();
    while (line != null && !endBlockLineEncountered) {
        line = stripCommentsAndTrim(line);
        if (StringUtils.isBlank(line)) {
            continue;
        }

        StringTokenizer strTok = new StringTokenizer(line);
        if (!strTok.hasMoreTokens()) {
            LOG.error("Cannot find COLUMN_DEF_STRING");
            throw new RuntimeException();
        }

        String command = strTok.nextToken();
        if (command.equalsIgnoreCase(GeneralLedgerConstants.Reconciliation.COLUMN_DEF_STRING)) {
            if (!strTok.hasMoreTokens()) {
                LOG.error("Cannot find COLUMN_DEF_STRING");
                throw new RuntimeException();
            }
            String fieldName = strTok.nextToken();
            if (!strTok.hasMoreTokens()) {
                LOG.error("Cannot find COLUMN_DEF_STRING");
                throw new RuntimeException();
            }
            String columnAmountStr = strTok.nextToken();
            columnAmountStr = StringUtils.removeEnd(columnAmountStr, ";");

            KualiDecimal columnAmount = new KualiDecimal(columnAmountStr);
            ColumnReconciliation columnReconciliation = new ColumnReconciliation();
            columnReconciliation.setFieldName(fieldName);
            columnReconciliation.setDollarAmount(columnAmount);
            reconciliationBlock.addColumn(columnReconciliation);
            linesInBlock++;
        } else if (command.equalsIgnoreCase(GeneralLedgerConstants.Reconciliation.CHECKSUM_DEF_STRING)) {
            if (!strTok.hasMoreTokens()) {
                LOG.error("Cannot find CHECKSUM_DEF_STRING");
                throw new RuntimeException();
            }
            String checksumStr = strTok.nextToken();
            checksumStr = StringUtils.removeEnd(checksumStr, ";");

            int checksum = Integer.parseInt(checksumStr);

            if (checksum != linesInBlock) {
                LOG.error("Check Sum String is not same as Lines in Block");
                throw new RuntimeException();
            }
            break;
        } else {
            LOG.error("Cannot find any fields");
            throw new RuntimeException();
        }

        line = bufReader.readLine();
    }
    return reconciliationBlock;
}

From source file:org.kuali.kfs.gl.service.impl.OriginEntryGroupServiceImpl.java

protected File getDataFile(File doneFile) {
    String doneFileAbsPath = doneFile.getAbsolutePath();
    if (!doneFileAbsPath.endsWith(GeneralLedgerConstants.BatchFileSystem.DONE_FILE_EXTENSION)) {
        throw new IllegalArgumentException(
                "Done file name must end with " + GeneralLedgerConstants.BatchFileSystem.DONE_FILE_EXTENSION);
    }/*from w ww.j a  va 2  s  .  co m*/
    String dataFileAbsPath = StringUtils.removeEnd(doneFileAbsPath,
            GeneralLedgerConstants.BatchFileSystem.DONE_FILE_EXTENSION)
            + GeneralLedgerConstants.BatchFileSystem.EXTENSION;
    File dataFile = new File(dataFileAbsPath);
    if (!dataFile.exists() || !dataFile.canRead()) {
        LOG.error("Cannot find/read data file " + dataFileAbsPath);
        return null;
    }
    return dataFile;
}

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

/**
 * generate the name of a companion file of the given file with the given companion file extension
 *
 * @param fileAbsPath the given file/*from  w ww .j ava 2s  .com*/
 * @param fileExtension the extension of the given file
 * @param companionFileExtension the given companion file extension
 * @return the name of a companion file of the given file with the given companion file extension
 */
protected String getCompanionFileName(String fileAbsPath, String fileExtension, String companionFileExtension) {
    return StringUtils.removeEnd(fileAbsPath, fileExtension).concat(companionFileExtension);
}

From source file:org.kuali.kfs.pdp.businessobject.BankChangeHistory.java

public String getOriginalBankCodeList() {
    String commaSeparatedOriginalBankCodeList = "";

    for (PaymentGroupHistory paymentGroupHistory : this.getPaymentGroup().getPaymentGroupHistory()) {
        if (!StringUtils.isEmpty(paymentGroupHistory.getOrigBankCode()))
            commaSeparatedOriginalBankCodeList = commaSeparatedOriginalBankCodeList
                    + paymentGroupHistory.getOrigBankCode() + ", ";
    }/*from   ww w . j  a v  a  2  s. com*/

    commaSeparatedOriginalBankCodeList = StringUtils.strip(commaSeparatedOriginalBankCodeList);
    commaSeparatedOriginalBankCodeList = StringUtils.removeEnd(commaSeparatedOriginalBankCodeList, ",");

    return commaSeparatedOriginalBankCodeList;
}

From source file:org.kuali.kpme.core.ListConverter.java

@Override
public Object sqlToJava(Object arg0) throws ConversionException {

    String selectedValues = arg0.toString();
    List<String> aList = new ArrayList<String>();

    selectedValues = StringUtils.removeStart(selectedValues, "[");
    selectedValues = StringUtils.removeEnd(selectedValues, "]");
    String[] values = StringUtils.split(selectedValues, ",");

    for (String value : values) {
        aList.add(StringUtils.strip(value, " ")); // strip whitespace from the start and end
    }/*from   ww w .  j  av  a  2  s .  com*/

    return aList;
}

From source file:org.kuali.kpme.core.util.ClearDatabaseLifecycle.java

protected void clearTables(final PlatformTransactionManager transactionManager, final DataSource dataSource,
        final String schemaName) {
    LOG.info("Clearing tables for schema " + schemaName);
    Assert.assertNotNull("DataSource could not be located.", dataSource);

    if (schemaName == null || schemaName.equals("")) {
        Assert.fail("Empty schema name given");
    }/*from w  ww. ja v a  2s  .  c  o m*/
    new TransactionTemplate(transactionManager).execute(new TransactionCallback<Object>() {
        public Object doInTransaction(final TransactionStatus status) {
            verifyTestEnvironment(dataSource);
            return new JdbcTemplate(dataSource).execute(new StatementCallback<Object>() {
                public Object doInStatement(Statement statement) throws SQLException {
                    final List<String> reEnableConstraints = new ArrayList<String>();
                    List<List<String>> tableLists = new ArrayList<List<String>>(2);
                    tableLists.add(TABLES_TO_CLEAR);
                    tableLists.add(alternativeTablesToClear);
                    for (List<String> list : tableLists) {
                        for (String tableName : list) {
                            //if there is an id name that doesnt follow convention check and limit accordingly
                            String idName = TABLE_TO_ID_MAP.get(tableName);
                            String deleteStatement = null;
                            Integer clearId = TABLE_START_CLEAR_ID.get(tableName) != null
                                    ? TABLE_START_CLEAR_ID.get(tableName)
                                    : START_CLEAR_ID;
                            if (idName == null) {
                                deleteStatement = "DELETE FROM " + tableName + " WHERE "
                                        + StringUtils.removeEnd(tableName, "_T") + "_ID" + " >= " + clearId;
                            } else {
                                deleteStatement = "DELETE FROM " + tableName + " WHERE " + idName + " >= "
                                        + clearId;
                            }

                            LOG.debug("Clearing contents using statement ->" + deleteStatement + "<-");
                            statement.addBatch(deleteStatement);
                        }
                    }

                    for (final String constraint : reEnableConstraints) {
                        LOG.debug("Enabling constraints using statement ->" + constraint + "<-");
                        statement.addBatch(constraint);
                    }
                    statement.executeBatch();
                    return null;
                }
            });
        }
    });
    LOG.info("Tables successfully cleared for schema " + schemaName);
}

From source file:org.kuali.kra.common.specialreview.service.impl.SpecialReviewServiceImpl.java

/**
 * {@inheritDoc}/*from w w  w .j  a  va2 s. co m*/
 * @see org.kuali.kra.common.specialreview.service.SpecialReviewService#getProtocolSaveLocationPrefix(java.util.Map)
 */
public String getProtocolSaveLocationPrefix(Map<String, String[]> parameters) {
    String prefix = null;

    for (String parameterName : parameters.keySet()) {
        if (parameterName.endsWith(PROTOCOL_NUMBER)) {
            prefix = StringUtils.removeEnd(parameterName, PROTOCOL_NUMBER);
            break;
        }
    }

    return prefix;
}

From source file:org.kuali.kra.questionnaire.question.Question.java

/**
 * /*from  w  w w. j  a va 2 s  .c o m*/
 * This method returns the descriptive text of the lookupClass
 * @return descriptive text
 */
public String getLookupClassDescription() {
    if (this.lookupClass != null) {
        DataDictionaryService dataDictionaryService = KraServiceLocator.getService(DataDictionaryService.class);
        Map<String, BusinessObjectEntry> businessObjectEntries = dataDictionaryService.getDataDictionary()
                .getBusinessObjectEntries();
        return StringUtils.removeEnd(
                businessObjectEntries.get(this.lookupClass).getLookupDefinition().getTitle().trim(), " Lookup");
    } else {
        return "";
    }
}

From source file:org.kuali.rice.core.api.search.SearchExpressionUtils.java

public static String parsePostfixUnaryOperatorValue(SearchOperator operator, String expression) {
    return StringUtils.removeEnd(expression.trim(), operator.op()).trim();
}