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.kfs.gl.batch.EnterpriseFeederFileSetType.java
/** * Returns done file name for a specific user and file user identifier * //from ww w . j a v a 2s.c o m * @param user the user who uploaded or will upload the file * @param fileUserIdentifier the file identifier * @return String done file name * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#getDoneFileName(org.kuali.rice.kim.api.identity.Person, java.lang.String) */ public String getDoneFileName(Person user, String fileUserIdentifer, Date creationDate) { DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); StringBuilder buf = new StringBuilder(); fileUserIdentifer = StringUtils.deleteWhitespace(fileUserIdentifer); fileUserIdentifer = StringUtils.remove(fileUserIdentifer, FILE_NAME_PART_DELIMITER); buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()) .append(FILE_NAME_PART_DELIMITER).append(fileUserIdentifer).append(FILE_NAME_PART_DELIMITER) .append(dateTimeService.toDateTimeStringForFilename(creationDate)).append(getDoneFileExtension()); return buf.toString(); }
From source file:org.kuali.kfs.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 .jav a 2s .c om*/ * @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(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.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(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.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, KFSConstants.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) && KFSConstants.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(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.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(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.Collector.TRAILER_ERROR_AMOUNTNOMATCH2, totalGlEntries.toString(), batch.getTotalAmount().toString()); trailerTotalsMatch = false; } } return trailerTotalsMatch; }
From source file:org.kuali.kfs.module.ar.batch.CustomerInvoiceWriteoffBatchInputFileType.java
/** * //w w w . j av a 2 s .c om * @see org.kuali.kfs.sys.batch.BatchInputFileType#getFileName(org.kuali.rice.kim.api.identity.Person, java.lang.Object, java.lang.String) */ public String getFileName(String principalName, Object parsedFileContents, String fileUserIdentifer) { // start with the batch-job-prefix StringBuilder fileName = new StringBuilder(FILE_NAME_PREFIX); // add the logged-in user name if there is one, otherwise use a sensible default fileName.append(FILE_NAME_DELIM + principalName); // if the user specified an identifying label, then use it if (StringUtils.isNotBlank(fileUserIdentifer)) { fileName.append(FILE_NAME_DELIM + fileUserIdentifer); } // stick a time stamp on the end fileName.append(FILE_NAME_DELIM + dateTimeService.toString(dateTimeService.getCurrentTimestamp(), "yyyyMMdd_HHmmss")); // stupid spaces, begone! return StringUtils.remove(fileName.toString(), " "); }
From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerLoadServiceImpl.java
/** * @see org.kuali.kfs.module.ar.batch.service.CustomerLoadService#getFileName() * * this is abstracted from the CustomerLoadInputFileType *///from w ww . j ava 2 s . c o m @Override public String getFileName(String principalName, String fileUserIdentifer, String prefix, String delim) { // start with the batch-job-prefix StringBuilder fileName = new StringBuilder(delim); // add the logged-in user name if there is one, otherwise use a sensible default fileName.append(delim + principalName); // if the user specified an identifying lable, then use it if (StringUtils.isNotBlank(fileUserIdentifer)) { fileName.append(delim + fileUserIdentifer); } // stick a timestamp on the end fileName.append(delim + dateTimeService.toString(dateTimeService.getCurrentTimestamp(), "yyyyMMdd_HHmmss")); // stupid spaces, begone! return StringUtils.remove(fileName.toString(), " "); }
From source file:org.kuali.kfs.module.ar.report.service.impl.AccountsReceivableReportServiceImpl.java
/** * This method.../*from www . j a v a 2 s. c om*/ * * @param mapKey * @param amountToAdd * @param invoiceMap */ protected void addAgingAmountToInvoiceMap(String mapKey, KualiDecimal amountToAdd, Map<String, String> invoiceMap) { BigDecimal amount = BigDecimal.ZERO; String currentAmount = invoiceMap.get(mapKey); if (StringUtils.isNotEmpty(currentAmount)) { try { amount = new BigDecimal(StringUtils.remove(currentAmount, ',')); } catch (NumberFormatException nfe) { LOG.error(currentAmount + " is an invalid amount.", nfe); } } if (ObjectUtils.isNull(amountToAdd)) { amountToAdd = KualiDecimal.ZERO; } KualiDecimal newAmount = new KualiDecimal(amount.add(amountToAdd.bigDecimalValue())); invoiceMap.put(mapKey, currencyFormatter.format(newAmount).toString()); }
From source file:org.kuali.kfs.module.ar.report.service.impl.OCRLineServiceImpl.java
/** * @see org.kuali.kfs.module.ar.report.service.OCRLineService#generateOCRL(java.lang.String, java.lang.String) *///from w w w . j a v a 2 s . co m public String generateOCRLine(KualiDecimal amountDue, String customerNumber, String docNumber) { StringBuilder builder = new StringBuilder(70); String amount = StringUtils.remove(amountDue.toString(), '.'); builder.append(StringUtils.leftPad(amount, 12, '0')); builder.append(" "); if (docNumber != null) { builder.append(StringUtils.leftPad(docNumber, 11, '0')); builder.append(" "); } builder.append(StringUtils.leftPad(customerNumber, 9, '0')); builder.append(" "); builder.append(calculateCheckDigit(amount, customerNumber, docNumber)); return builder.toString(); }
From source file:org.kuali.kfs.module.bc.util.ImportRequestFileParsingHelper.java
/** * Parses line and creates BudgetConstructionRequestMove object. * * @param lineToParse/*from w ww .j a v a 2 s .com*/ * @param fieldSeperator * @param textDelimiter * @return the BudgetConstructionRequestMove or null if there was an error parsing the line */ public static BudgetConstructionRequestMove parseLine(String lineToParse, String fieldSeperator, String textDelimiter, boolean isAnnual) { List<String> attributes = new ArrayList<String>(); BudgetConstructionRequestMove budgetConstructionRequestMove = new BudgetConstructionRequestMove(); int expectedNumberOfSeparators = isAnnual ? 5 : 16; lineToParse = lineToParse.trim(); //check if line is in correct format if (!isLineCorrectlyFormatted(lineToParse, fieldSeperator, textDelimiter, isAnnual)) { return null; } if (textDelimiter.equalsIgnoreCase(BCConstants.RequestImportTextFieldDelimiter.NOTHING.getDelimiter())) { attributes.addAll(Arrays.asList(lineToParse.split( isFieldSeparatorSpecialCharacter(fieldSeperator) ? "\\" + fieldSeperator : fieldSeperator))); } else if (getEscapedFieldSeparatorCount(lineToParse, fieldSeperator, textDelimiter, isAnnual) == 0) { lineToParse = StringUtils.remove(lineToParse, textDelimiter); attributes.addAll(Arrays.asList(lineToParse.split( isFieldSeparatorSpecialCharacter(fieldSeperator) ? "\\" + fieldSeperator : fieldSeperator))); } else { int firstIndexOfTextDelimiter = 0; int nextIndexOfTextDelimiter = lineToParse.indexOf(textDelimiter, firstIndexOfTextDelimiter + 1); int expectedNumberOfTextDelimiters = 10; for (int i = 0; i < expectedNumberOfTextDelimiters / 2; i++) { attributes.add(lineToParse.substring(firstIndexOfTextDelimiter, nextIndexOfTextDelimiter) .replaceAll(textDelimiter, "")); firstIndexOfTextDelimiter = lineToParse.indexOf(textDelimiter, nextIndexOfTextDelimiter + 1); nextIndexOfTextDelimiter = lineToParse.indexOf(textDelimiter, firstIndexOfTextDelimiter + 1); } String remainingNonStringValuesToParse = lineToParse .substring(lineToParse.lastIndexOf(textDelimiter + 1)); attributes.addAll(Arrays.asList(remainingNonStringValuesToParse.split( isFieldSeparatorSpecialCharacter(fieldSeperator) ? "\\" + fieldSeperator : fieldSeperator))); } // catch the short list case if (attributes.size() < (expectedNumberOfSeparators + 1)) { return null; } budgetConstructionRequestMove.setChartOfAccountsCode(attributes.get(0)); budgetConstructionRequestMove.setAccountNumber(attributes.get(1)); budgetConstructionRequestMove.setSubAccountNumber(attributes.get(2)); budgetConstructionRequestMove.setFinancialObjectCode(attributes.get(3)); budgetConstructionRequestMove.setFinancialSubObjectCode(attributes.get(4)); try { if (isAnnual) { budgetConstructionRequestMove .setAccountLineAnnualBalanceAmount(new KualiInteger(Integer.parseInt(attributes.get(5)))); } else { budgetConstructionRequestMove.setFinancialDocumentMonth1LineAmount( new KualiInteger(Integer.parseInt(attributes.get(5)))); budgetConstructionRequestMove.setFinancialDocumentMonth2LineAmount( new KualiInteger(Integer.parseInt(attributes.get(6)))); budgetConstructionRequestMove.setFinancialDocumentMonth3LineAmount( new KualiInteger(Integer.parseInt(attributes.get(7)))); budgetConstructionRequestMove.setFinancialDocumentMonth4LineAmount( new KualiInteger(Integer.parseInt(attributes.get(8)))); budgetConstructionRequestMove.setFinancialDocumentMonth5LineAmount( new KualiInteger(Integer.parseInt(attributes.get(9)))); budgetConstructionRequestMove.setFinancialDocumentMonth6LineAmount( new KualiInteger(Integer.parseInt(attributes.get(10)))); budgetConstructionRequestMove.setFinancialDocumentMonth7LineAmount( new KualiInteger(Integer.parseInt(attributes.get(11)))); budgetConstructionRequestMove.setFinancialDocumentMonth8LineAmount( new KualiInteger(Integer.parseInt(attributes.get(12)))); budgetConstructionRequestMove.setFinancialDocumentMonth9LineAmount( new KualiInteger(Integer.parseInt(attributes.get(13)))); budgetConstructionRequestMove.setFinancialDocumentMonth10LineAmount( new KualiInteger(Integer.parseInt(attributes.get(14)))); budgetConstructionRequestMove.setFinancialDocumentMonth11LineAmount( new KualiInteger(Integer.parseInt(attributes.get(15)))); budgetConstructionRequestMove.setFinancialDocumentMonth12LineAmount( new KualiInteger(Integer.parseInt(attributes.get(16)))); } } catch (NumberFormatException e) { return null; } return budgetConstructionRequestMove; }
From source file:org.kuali.kfs.module.cam.batch.service.impl.AssetBarcodeInventoryLoadServiceImpl.java
/** * @see org.kuali.module.cams.service.AssetBarcodeInventoryLoadService#isFileFormatValid(java.io.File) *//* w w w .j av a 2s .c o m*/ public boolean isFileFormatValid(File file) { LOG.debug("isFileFormatValid(File file) - start"); String fileName = file.getName(); BufferedReader input = null; // Getting the length of each field that needs to be validated Integer campusTagNumberMaxLength = dataDictionaryService.getAttributeMaxLength(Asset.class, CamsPropertyConstants.Asset.CAMPUS_TAG_NUMBER); Integer inventoryScannedCodeMaxLength = new Integer(1); Integer InventoryDateMaxLength = dataDictionaryService.getAttributeMaxLength( BarcodeInventoryErrorDetail.class, CamsPropertyConstants.BarcodeInventory.INVENTORY_DATE); Integer campusCodeMaxLength = dataDictionaryService.getAttributeMaxLength(Asset.class, CamsPropertyConstants.Asset.CAMPUS_CODE); Integer buildingCodeMaxLength = dataDictionaryService.getAttributeMaxLength(Asset.class, CamsPropertyConstants.Asset.BUILDING_CODE); Integer buildingRoomNumberMaxLength = dataDictionaryService.getAttributeMaxLength(Asset.class, CamsPropertyConstants.Asset.BUILDING_ROOM_NUMBER); Integer buildingSubRoomNumberMaxLength = dataDictionaryService.getAttributeMaxLength(Asset.class, CamsPropertyConstants.Asset.BUILDING_SUB_ROOM_NUMBER); Integer conditionCodeMaxLength = dataDictionaryService.getAttributeMaxLength(Asset.class, CamsPropertyConstants.Asset.CONDITION_CODE); // Getting the label of each field from data dictionary. String campusTagNumberLabel = dataDictionaryService.getAttributeLabel(Asset.class, CamsPropertyConstants.Asset.CAMPUS_TAG_NUMBER); String inventoryScannedCodeLabel = dataDictionaryService.getAttributeLabel(Asset.class, CamsPropertyConstants.BarcodeInventory.UPLOAD_SCAN_INDICATOR); String InventoryDateLabel = dataDictionaryService.getAttributeLabel(BarcodeInventoryErrorDetail.class, CamsPropertyConstants.BarcodeInventory.INVENTORY_DATE); String campusCodeLabel = dataDictionaryService.getAttributeLabel(Asset.class, CamsPropertyConstants.Asset.CAMPUS_CODE); String buildingCodeLabel = dataDictionaryService.getAttributeLabel(Asset.class, CamsPropertyConstants.Asset.BUILDING_CODE); String buildingRoomNumberLabel = dataDictionaryService.getAttributeLabel(Asset.class, CamsPropertyConstants.Asset.BUILDING_ROOM_NUMBER); String buildingSubRoomNumberLabel = dataDictionaryService.getAttributeLabel(Asset.class, CamsPropertyConstants.Asset.BUILDING_SUB_ROOM_NUMBER); String conditionCodeLabel = dataDictionaryService.getAttributeLabel(Asset.class, CamsPropertyConstants.Asset.CONDITION_CODE); try { int recordCount = 0; String errorMsg = ""; String errorMessage = ""; boolean proceed = true; String lengthError = "exceeds maximum length"; input = new BufferedReader(new FileReader(file)); String line = null; while ((line = input.readLine()) != null) { recordCount++; errorMsg = ""; line = StringUtils.remove(line, "\""); String[] column = org.springframework.util.StringUtils.delimitedListToStringArray(line, ","); if (MAX_NUMBER_OF_COLUMNS < column.length) { // Error more columns that allowed. put it in the constants class. errorMsg += " Barcode inventory file has record(s) with more than " + MAX_NUMBER_OF_COLUMNS + " columns\n"; proceed = false; } else if (MAX_NUMBER_OF_COLUMNS > column.length) { errorMsg += " Barcode inventory file has record(s) with less than " + MAX_NUMBER_OF_COLUMNS + " columns\n"; proceed = false; } else { // Validating length of each field if (column[0].length() > campusTagNumberMaxLength.intValue()) { errorMsg += ", " + campusTagNumberLabel; } if (column[1].length() > inventoryScannedCodeMaxLength.intValue()) { errorMsg += ", " + inventoryScannedCodeLabel; } if (column[2].length() > InventoryDateMaxLength.intValue()) { errorMsg += ", " + InventoryDateLabel; } if (column[3].length() > campusCodeMaxLength.intValue()) { errorMsg += ", " + campusCodeLabel; } if (column[4].length() > buildingCodeMaxLength.intValue()) { errorMsg += ", " + buildingCodeLabel; } if (column[5].length() > buildingRoomNumberMaxLength.intValue()) { errorMsg += ", " + buildingRoomNumberLabel; } if (column[6].length() > buildingSubRoomNumberMaxLength.intValue()) { errorMsg += ", " + buildingSubRoomNumberLabel; } if (column[7].length() > conditionCodeMaxLength.intValue()) { errorMsg += ", " + conditionCodeLabel; } if (!StringUtils.isBlank(errorMsg)) { errorMsg += " " + lengthError; } // Validating other than the length of the fields if (!column[1].equals(CamsConstants.BarCodeInventory.BCI_SCANED_INTO_DEVICE) && !column[1].equals(CamsConstants.BarCodeInventory.BCI_MANUALLY_KEYED_CODE)) { errorMsg += ", " + inventoryScannedCodeLabel + " is invalid"; } // validate date if (!validateDate(column[2])) { errorMsg += ", " + InventoryDateLabel + " is invalid"; } } if (!StringUtils.isBlank(errorMsg)) { errorMsg = "Error on record number " + recordCount + ": " + errorMsg.substring(2) + "\n"; GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_CUSTOM, errorMsg); errorMessage += errorMsg; LOG.error(errorMsg); } if (!proceed) break; } if (!StringUtils.isBlank(errorMessage)) { return false; } return true; } catch (FileNotFoundException e1) { LOG.error("file to parse not found " + fileName, e1); throw new RuntimeException( "Cannot find the file requested to be parsed " + fileName + " " + e1.getMessage(), e1); } catch (Exception e) { LOG.error("Error running file validation - File: " + fileName, e); throw new IllegalArgumentException("Error running file validation - File: " + fileName); } finally { LOG.debug("isFileFormatValid(File file) - end"); try { if (input != null) { input.close(); } } catch (IOException ex) { LOG.error("isFileFormatValid() error closing file.", ex); } } }
From source file:org.kuali.kfs.module.cam.batch.service.impl.AssetBarcodeInventoryLoadServiceImpl.java
/** * @see org.kuali.module.cams.service.AssetBarCodeInventoryLoadService#processFile(java.io.File) *//*from ww w.j a va 2 s.c o m*/ public boolean processFile(File file, AssetBarCodeInventoryInputFileForm form) { LOG.debug("processFile(File file) - start"); // Removing *.done files that are created automatically by the framework. this.removeDoneFile(file); BufferedReader input = null; String fileName = file.getName(); String day; String month; String year; String hours; String minutes; String seconds; boolean isValid = true; SimpleDateFormat formatter = new SimpleDateFormat( CamsConstants.DateFormats.MONTH_DAY_YEAR + " " + CamsConstants.DateFormats.MILITARY_TIME, Locale.US); formatter.setLenient(false); BarcodeInventoryErrorDetail barcodeInventoryErrorDetail; List<BarcodeInventoryErrorDetail> barcodeInventoryErrorDetails = new ArrayList<BarcodeInventoryErrorDetail>(); List<BarcodeInventoryErrorDocument> barcodeInventoryErrorDocuments = new ArrayList<BarcodeInventoryErrorDocument>(); try { Long ln = new Long(1); input = new BufferedReader(new FileReader(file)); String line = null; while ((line = input.readLine()) != null) { line = StringUtils.remove(line, "\""); String[] lineStrings = org.springframework.util.StringUtils.delimitedListToStringArray(line, ","); // Parsing date so it can be validated. lineStrings[2] = StringUtils.rightPad(lineStrings[2].trim(), 14, "0"); day = lineStrings[2].substring(0, 2); month = lineStrings[2].substring(2, 4); year = lineStrings[2].substring(4, 8); hours = lineStrings[2].substring(8, 10); minutes = lineStrings[2].substring(10, 12); seconds = lineStrings[2].substring(12); String stringDate = month + "/" + day + "/" + year + " " + hours + ":" + minutes + ":" + seconds; Timestamp timestamp = null; // If date has invalid format set its value to null try { timestamp = new Timestamp(formatter.parse(stringDate).getTime()); } catch (Exception e) { } // Its set to null because for some reason java parses "00000000000000" as 0002-11-30 if (lineStrings[2].equals(StringUtils.repeat("0", 14))) { timestamp = null; } barcodeInventoryErrorDetail = new BarcodeInventoryErrorDetail(); barcodeInventoryErrorDetail.setUploadRowNumber(ln); barcodeInventoryErrorDetail.setAssetTagNumber(lineStrings[0].trim()); barcodeInventoryErrorDetail.setUploadScanIndicator( lineStrings[1].equals(CamsConstants.BarCodeInventory.BCI_SCANED_INTO_DEVICE)); barcodeInventoryErrorDetail.setUploadScanTimestamp(timestamp); barcodeInventoryErrorDetail.setCampusCode(lineStrings[3].trim().toUpperCase()); barcodeInventoryErrorDetail.setBuildingCode(lineStrings[4].trim().toUpperCase()); barcodeInventoryErrorDetail.setBuildingRoomNumber(lineStrings[5].trim().toUpperCase()); barcodeInventoryErrorDetail.setBuildingSubRoomNumber(lineStrings[6].trim().toUpperCase()); barcodeInventoryErrorDetail.setAssetConditionCode(lineStrings[7].trim().toUpperCase()); barcodeInventoryErrorDetail .setErrorCorrectionStatusCode(CamsConstants.BarCodeInventoryError.STATUS_CODE_ERROR); barcodeInventoryErrorDetail.setCorrectorUniversalIdentifier( GlobalVariables.getUserSession().getPerson().getPrincipalId()); barcodeInventoryErrorDetails.add(barcodeInventoryErrorDetail); ln++; } processBarcodeInventory(barcodeInventoryErrorDetails, form); return true; } catch (FileNotFoundException e1) { LOG.error("file to parse not found " + fileName, e1); throw new RuntimeException( "Cannot find the file requested to be parsed " + fileName + " " + e1.getMessage(), e1); } catch (Exception ex) { LOG.error("Error reading file", ex); throw new IllegalArgumentException("Error reading file: " + ex.getMessage(), ex); } finally { LOG.debug("processFile(File file) - End"); try { if (input != null) { input.close(); } } catch (IOException ex) { LOG.error("loadFlatFile() error closing file.", ex); } } }
From source file:org.kuali.kfs.module.cg.service.impl.CfdaServiceImpl.java
/** * @return//from w ww .ja va2 s. c o m * @throws IOException */ public SortedMap<String, CFDA> getGovCodes() throws IOException { Calendar calendar = dateTimeService.getCurrentCalendar(); SortedMap<String, CFDA> govMap = new TreeMap<String, CFDA>(); // ftp://ftp.cfda.gov/programs09187.csv String govURL = parameterService.getParameterValueAsString(CfdaBatchStep.class, KFSConstants.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 isLoggedIn = ftp.login("anonymous", ""); if (!isLoggedIn) { 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; }