List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:org.kuali.maven.plugins.externals.DirSyncMojo.java
protected List<String> getRelativePaths(File dir, List<File> files) throws IOException { String path = dir.getCanonicalPath(); List<String> paths = new ArrayList<String>(); for (File file : files) { String filePath = file.getCanonicalPath(); String s = StringUtils.remove(filePath, path); paths.add(s);//from w w w .ja v a2s . c o m } return paths; }
From source file:org.kuali.ole.coa.service.impl.CfdaServiceImpl.java
/** * @return//from ww w . j a va2 s . co m * @throws IOException */ public SortedMap<String, CFDA> getGovCodes() throws IOException { Calendar calendar = SpringContext.getBean(DateTimeService.class).getCurrentCalendar(); SortedMap<String, CFDA> govMap = new TreeMap<String, CFDA>(); // ftp://ftp.cfda.gov/programs09187.csv String govURL = SpringContext.getBean(ParameterService.class).getParameterValueAsString(CfdaBatchStep.class, OLEConstants.SOURCE_URL_PARAMETER); String fileName = StringUtils.substringAfterLast(govURL, "/"); govURL = StringUtils.substringBeforeLast(govURL, "/"); if (StringUtils.contains(govURL, "ftp://")) { govURL = StringUtils.remove(govURL, "ftp://"); } // need to pull off the '20' in 2009 String year = "" + calendar.get(Calendar.YEAR); year = year.substring(2, 4); fileName = fileName + year; // the last 3 numbers in the file name are the day of the year, but the files are from "yesterday" fileName = fileName + String.format("%03d", calendar.get(Calendar.DAY_OF_YEAR) - 1); fileName = fileName + ".csv"; LOG.info("Getting government file: " + fileName + " for update"); InputStream inputStream = null; FTPClient ftp = new FTPClient(); try { ftp.connect(govURL); int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { LOG.error("FTP connection to server not established."); throw new IOException("FTP connection to server not established."); } boolean loggedIn = ftp.login("anonymous", ""); if (!loggedIn) { LOG.error("Could not login as anonymous."); throw new IOException("Could not login as anonymous."); } LOG.info("Successfully connected and logged in"); ftp.enterLocalPassiveMode(); inputStream = ftp.retrieveFileStream(fileName); if (inputStream != null) { LOG.info("reading input stream"); InputStreamReader screenReader = new InputStreamReader(inputStream); BufferedReader screen = new BufferedReader(screenReader); CSVReader csvReader = new CSVReader(screenReader, ',', '"', 1); List<String[]> lines = csvReader.readAll(); for (String[] line : lines) { String title = line[0]; String number = line[1]; CFDA cfda = new CFDA(); cfda.setCfdaNumber(number); cfda.setCfdaProgramTitleName(title); govMap.put(number, cfda); } } ftp.logout(); ftp.disconnect(); } finally { if (ftp.isConnected()) { ftp.disconnect(); } } return govMap; }
From source file:org.kuali.ole.gl.batch.service.impl.CollectorHelperServiceImpl.java
/** * Checks the batch total line count and amounts against the trailer. Any errors will be contained in GlobalVariables.MessageMap * /*from w w w .j a va 2s.c o m*/ * @param batch - batch to check totals for * @return boolean - true if validation was successful, false it not */ protected boolean checkTrailerTotals(CollectorBatch batch, CollectorReportData collectorReportData, MessageMap messageMap) { boolean trailerTotalsMatch = true; int actualRecordCount = batch.getOriginEntries().size() + batch.getCollectorDetails().size(); if (actualRecordCount != batch.getTotalRecords()) { LOG.error("trailer check on total count did not pass, expected count: " + String.valueOf(batch.getTotalRecords()) + ", actual count: " + String.valueOf(actualRecordCount)); messageMap.putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.Collector.TRAILER_ERROR_COUNTNOMATCH, String.valueOf(batch.getTotalRecords()), String.valueOf(actualRecordCount)); trailerTotalsMatch = false; } OriginEntryTotals totals = batch.getOriginEntryTotals(); if (batch.getOriginEntries().size() == 0) { if (!KualiDecimal.ZERO.equals(batch.getTotalAmount())) { LOG.error("trailer total should be zero when there are no origin entries"); messageMap.putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.Collector.TRAILER_ERROR_AMOUNT_SHOULD_BE_ZERO); } return false; } // retrieve document types that balance by equal debits and credits Collection<String> documentTypes = new ArrayList<String>( parameterService.getParameterValuesAsString(CollectorStep.class, OLEConstants.SystemGroupParameterNames.COLLECTOR_EQUAL_DC_TOTAL_DOCUMENT_TYPES)); boolean equalDebitCreditTotal = false; for (String documentType : documentTypes) { documentType = StringUtils.remove(documentType, "*").toUpperCase(); if (batch.getOriginEntries().get(0).getFinancialDocumentTypeCode().startsWith(documentType) && OLEConstants.BALANCE_TYPE_ACTUAL .equals(batch.getOriginEntries().get(0).getFinancialBalanceTypeCode())) { equalDebitCreditTotal = true; } } if (equalDebitCreditTotal) { // credits must equal debits must equal total trailer amount if (!totals.getCreditAmount().equals(totals.getDebitAmount()) || !totals.getCreditAmount().equals(batch.getTotalAmount())) { LOG.error( "trailer check on total amount did not pass, debit should equal credit, should equal trailer total"); messageMap.putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.Collector.TRAILER_ERROR_AMOUNTNOMATCH1, totals.getCreditAmount().toString(), totals.getDebitAmount().toString(), batch.getTotalAmount().toString()); trailerTotalsMatch = false; } } else { // credits plus debits plus other amount must equal trailer KualiDecimal totalGlEntries = totals.getCreditAmount().add(totals.getDebitAmount()) .add(totals.getOtherAmount()); if (!totalGlEntries.equals(batch.getTotalAmount())) { LOG.error( "trailer check on total amount did not pass, sum of gl entry amounts should equal trailer total"); messageMap.putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.Collector.TRAILER_ERROR_AMOUNTNOMATCH2, totalGlEntries.toString(), batch.getTotalAmount().toString()); trailerTotalsMatch = false; } } return trailerTotalsMatch; }
From source file:org.kuali.ole.module.purap.util.ItemParserBase.java
/** * @see org.kuali.ole.module.purap.util.ItemParser#parseItem(org.apache.struts.upload.FormFile, java.lang.Class, java.lang.String) *///w w w . ja v a 2s . c om public List<PurApItem> importItems(FormFile itemFile, Class<? extends PurApItem> itemClass, String documentNumber) { // check input parameters try { checkItemClass(itemClass); checkItemFile(itemFile); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("unable to import items.", e); } // open input stream List<PurApItem> importedItems = new ArrayList<PurApItem>(); InputStream is; BufferedReader br; try { is = itemFile.getInputStream(); br = new BufferedReader(new InputStreamReader(is)); } catch (IOException e) { throw new IllegalArgumentException("unable to open import file in ItemParserBase.", e); } // parse items line by line lineNo = 0; boolean failed = false; String itemLine = null; try { while ((itemLine = br.readLine()) != null) { lineNo++; if (StringUtils .isBlank(StringUtils.remove(StringUtils.deleteWhitespace(itemLine), OLEConstants.COMMA))) { continue; } try { PurApItem item = parseItem(itemLine, itemClass, documentNumber); importedItems.add(item); } catch (ItemParserException e) { // continue to parse the rest of the items after the current item fails // error messages are already dealt with inside parseItem, so no need to do anything here failed = true; } } if (failed) { throw new ItemParserException("errors in parsing item lines in file " + itemFile.getFileName(), ERROR_ITEMPARSER_ITEM_LINE, itemFile.getFileName()); } } catch (IOException e) { throw new IllegalArgumentException("unable to read line from BufferReader in ItemParserBase", e); } finally { try { br.close(); } catch (IOException e) { throw new IllegalArgumentException("unable to close BufferReader in ItemParserBase", e); } } return importedItems; }
From source file:org.kuali.ole.pdp.batch.PaymentInputFileType.java
/** * @see org.kuali.ole.sys.batch.BatchInputFileType#getFileName(org.kuali.rice.kim.api.identity.Person, java.lang.Object, * java.lang.String)/*from w w w.j av a 2s .c o m*/ */ public String getFileName(String principalName, Object parsedFileContents, String fileUserIdentifer) { Timestamp currentTimestamp = dateTimeService.getCurrentTimestamp(); String fileName = PdpConstants.PDP_FILE_UPLOAD_FILE_PREFIX + "_" + principalName; if (StringUtils.isNotBlank(fileUserIdentifer)) { fileName += "_" + StringUtils.remove(fileUserIdentifer, " "); } fileName += "_" + dateTimeService.toString(currentTimestamp, "yyyyMMdd_HHmmss"); // remove spaces in filename fileName = StringUtils.remove(fileName, " "); return fileName; }
From source file:org.kuali.ole.select.batch.MarcInputFileType.java
/** * No additional information is added to bibinfo batch files. * * @see org.kuali.ole.sys.batch.BatchInputFileType#getFileName(org.kuali.rice.kim.api.identity.Person, java.lang.Object, * java.lang.String)//from w w w.j a v a2 s. c o m */ public String getFileName(String principalName, Object parsedFileContents, String userIdentifier, String destinationPath) { LOG.debug("Inside MarcFileType.getFileName method.."); String fileName = "marcinfo_" + principalName; if (StringUtils.isNotBlank(userIdentifier)) { fileName += "_" + userIdentifier; } // destinationPath = "staging/select/vendortransmissionfiles"; // LOG.info("--------------file.Separator---------------"+os.toUpperCase()); String os = System.getProperty("os.name"); if (LOG.isDebugEnabled()) LOG.debug("--------------file.Separator---------------" + os.toUpperCase()); String separator = ""; if (os.toUpperCase().contains("WIN")) { separator = "\\"; } else { separator = "/"; } if (LOG.isDebugEnabled()) { LOG.debug("--------------destinationPath---------------" + destinationPath); } destinationPath = destinationPath.replaceAll("\\" + separator, "__"); if (LOG.isDebugEnabled()) { LOG.debug("--------------separator---------------" + separator); LOG.debug("--------------destinationPath 1---------------" + destinationPath); } fileName += "--" + destinationPath; fileName += "--" + dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate()); // remove spaces in filename fileName = StringUtils.remove(fileName, " "); return fileName; }
From source file:org.kuali.ole.select.batch.OrdInputFileType.java
/** * No additional information is added to bibinfo batch files. * * @see org.kuali.ole.sys.batch.BatchInputFileType#getFileName(org.kuali.rice.kim.api.identity.Person, java.lang.Object, * java.lang.String)/*www . jav a 2 s. c o m*/ */ public String getFileName(String principalName, Object parsedFileContents, String userIdentifier, String destinationPath) { LOG.debug("Inside OrdInputFileType.getFileName method.."); String fileName = "ordinfo_" + principalName; if (StringUtils.isNotBlank(userIdentifier)) { fileName += "_" + userIdentifier; } // destinationPath = "staging/select/vendortransmissionfiles"; // LOG.info("--------------file.Separator---------------"+os.toUpperCase()); String os = System.getProperty("os.name"); if (LOG.isDebugEnabled()) LOG.debug("--------------file.Separator---------------" + os.toUpperCase()); String separator = ""; if (os.toUpperCase().contains("WIN")) { separator = "\\"; } else { separator = "/"; } if (LOG.isDebugEnabled()) { LOG.debug("--------------destinationPath---------------" + destinationPath); } destinationPath = destinationPath.replaceAll("\\" + separator, "__"); if (LOG.isDebugEnabled()) { LOG.debug("--------------separator---------------" + separator); LOG.debug("--------------destinationPath 1---------------" + destinationPath); } fileName += "--" + destinationPath; fileName += "--" + dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate()); // remove spaces in filename fileName = StringUtils.remove(fileName, " "); return fileName; }
From source file:org.kuali.ole.select.batch.RequisitionInputFileType.java
/** * No additional information is added to bibinfo batch files. * * @see org.kuali.ole.sys.batch.BatchInputFileType#getFileName(org.kuali.rice.kim.api.identity.Person, java.lang.Object, * java.lang.String)/*from w ww . j a v a 2 s.c o m*/ */ public String getFileName(String principalName, Object parsedFileContents, String userIdentifier) { LOG.debug("Inside RequisitionInputFileType.getFileName method.."); String fileName = "requisitioninfo_" + principalName; if (StringUtils.isNotBlank(userIdentifier)) { fileName += "_" + userIdentifier; } fileName += "_" + dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate()); // remove spaces in filename fileName = StringUtils.remove(fileName, " "); return fileName; }
From source file:org.kuali.ole.sys.businessobject.AccountingLineParserBase.java
/** * Calls the appropriate parseAccountingLine method * //from w ww.j ava2 s . c o m * @param stream * @param transactionalDocument * @param isSource * @return List */ protected List<AccountingLine> importAccountingLines(String fileName, InputStream stream, AccountingDocument transactionalDocument, boolean isSource) { List<AccountingLine> importedAccountingLines = new ArrayList<AccountingLine>(); this.fileName = fileName; BufferedReader br = new BufferedReader(new InputStreamReader(stream)); try { String accountingLineAsString = null; lineNo = 0; while ((accountingLineAsString = br.readLine()) != null) { lineNo++; if (StringUtils.isBlank(StringUtils.remove(StringUtils.deleteWhitespace(accountingLineAsString), OLEConstants.COMMA))) { continue; } AccountingLine accountingLine = null; try { if (isSource) { accountingLine = parseSourceAccountingLine(transactionalDocument, accountingLineAsString); } else { accountingLine = parseTargetAccountingLine(transactionalDocument, accountingLineAsString); } validateImportedAccountingLine(accountingLine, accountingLineAsString); importedAccountingLines.add(accountingLine); } catch (AccountingLineParserException e) { GlobalVariables.getMessageMap().putError( (isSource ? "sourceAccountingLines" : "targetAccountingLines"), OLEKeyConstants.ERROR_ACCOUNTING_DOCUMENT_ACCOUNTING_LINE_IMPORT_GENERAL, new String[] { e.getMessage() }); } } } catch (IOException e) { throw new IllegalArgumentException("unable to readLine from bufferReader in accountingLineParserBase", e); } finally { try { br.close(); } catch (IOException e) { throw new IllegalArgumentException("unable to close bufferReader in accountingLineParserBase", e); } } return importedAccountingLines; }
From source file:org.kuali.ole.vnd.batch.VendorExcludeInputFileType.java
@Override public Object parse(byte[] fileByteContent) throws ParseException { LOG.info("Parsing Vendor Exclude Input File ..."); // create CSVReader, using conventional separator, quote, null escape char, skip first line, use strict quote, ignore leading white space int skipLine = 1; // skip the first line, which is the header line Reader inReader = new InputStreamReader(new ByteArrayInputStream(fileByteContent)); CSVReader reader = new CSVReader(inReader, ',', '"', Character.MIN_VALUE); List<DebarredVendorDetail> debarredVendors = new ArrayList<DebarredVendorDetail>(); String[] nextLine;// w ww . j a v a 2 s . c o m DebarredVendorDetail vendor; int lineNumber = skipLine; try { while ((nextLine = reader.readNext()) != null) { lineNumber++; LOG.debug("Line " + lineNumber + ": " + nextLine[0]); vendor = new DebarredVendorDetail(); boolean emptyLine = true; // this should never happen, as for an empty line, CSVReader.readNext returns a string array with an empty string as the only element // but just in case somehow a zero sized array is returned, we skip it. if (nextLine.length == 0) { continue; } StringBuffer name = new StringBuffer(); // if the name field is not empty, use that as vendor name if (StringUtils.isNotEmpty(nextLine[0])) { name.append(nextLine[0]); } // otherwise, there should be a first/middle/last name, which we concatenate into vendor name else { if (nextLine.length > 1 && !StringUtils.isNotEmpty(nextLine[1])) { name.append(" " + nextLine[1]); } if (nextLine.length > 2 && !StringUtils.isNotEmpty(nextLine[2])) { name.append(" " + nextLine[2]); } if (nextLine.length > 3 && !StringUtils.isNotEmpty(nextLine[3])) { name.append(" " + nextLine[3]); } if (nextLine.length > 4 && !StringUtils.isNotEmpty(nextLine[4])) { name.append(" " + nextLine[4]); } if (nextLine.length > 5 && StringUtils.isNotEmpty(nextLine[5])) { name.append(" " + nextLine[5]); } } if (StringUtils.isNotEmpty(name.toString())) { vendor.setName(StringUtils.left(name.toString(), FIELD_SIZES[0])); emptyLine = false; } if (nextLine.length > 6 && StringUtils.isNotEmpty(nextLine[6])) { vendor.setAddress1(StringUtils.left(nextLine[6], FIELD_SIZES[1])); emptyLine = false; } if (nextLine.length > 7 && StringUtils.isNotEmpty(nextLine[7])) { vendor.setAddress2(StringUtils.left(nextLine[7], FIELD_SIZES[2])); emptyLine = false; } if (nextLine.length > 8 && StringUtils.isNotEmpty(nextLine[8])) { vendor.setCity(StringUtils.left(nextLine[8], FIELD_SIZES[3])); emptyLine = false; } if (nextLine.length > 9 && StringUtils.isNotEmpty(nextLine[9])) { vendor.setProvince(StringUtils.left(nextLine[9], FIELD_SIZES[4])); emptyLine = false; } if (nextLine.length > 10 && StringUtils.isNotEmpty(nextLine[10])) { vendor.setState(StringUtils.left(nextLine[10], FIELD_SIZES[5])); emptyLine = false; } if (nextLine.length > 11 && StringUtils.isNotEmpty(nextLine[11])) { vendor.setZip(StringUtils.left(nextLine[11], FIELD_SIZES[6])); emptyLine = false; } if (nextLine.length > 13 && StringUtils.isNotEmpty(nextLine[13])) { vendor.setAliases(StringUtils.left(StringUtils.remove(nextLine[13], "\""), FIELD_SIZES[7])); emptyLine = false; } if (nextLine.length > 18 && StringUtils.isNotEmpty(nextLine[18])) { vendor.setDescription(StringUtils.left(nextLine[18], FIELD_SIZES[8])); emptyLine = false; } if (emptyLine) { /* give warnings on a line that doesn't have any useful vendor info LOG.warn("Note: line " + lineNumber + " in the Vendor Exclude Input File is skipped since all parsed fields are empty."); */ // throw parser exception on a line that doesn't have any useful vendor info. // Since the file usually doesn't contain empty lines or lines with empty fields, this happening usually is a good indicator that // some line ahead has wrong data format, for ex, missing a quote on a field, which could mess up the following fields and lines. throw new ParseException("Line " + lineNumber + " in the Vendor Exclude Input File contains no valid field or only empty fields within quote pairs. Please check the lines ahead to see if any field is missing quotes."); } else { vendor.setLoadDate(new Date(new java.util.Date().getTime())); debarredVendors.add(vendor); } } } catch (IOException ex) { throw new ParseException( "Error reading Vendor Exclude Input File at line " + lineNumber + ": " + ex.getMessage()); } LOG.info("Total number of lines read from Vendor Exclude Input File: " + lineNumber); LOG.info("Total number of vendors parsed from Vendor Exclude Input File: " + debarredVendors.size()); return debarredVendors; }