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, String padStr) 

Source Link

Document

Right pad a String with a specified String.

Usage

From source file:org.kuali.kfs.gl.GeneralLedgerConstants.java

public static String getSpaceChartOfAccountsCode() {
    if (SPACE_CHART_OF_ACCOUNTS_CODE == null) {
        SPACE_CHART_OF_ACCOUNTS_CODE = StringUtils.rightPad("",
                SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginEntryFull.class,
                        KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE),
                ' ');
    }/*from www. j a v a  2  s. c  o m*/
    return SPACE_CHART_OF_ACCOUNTS_CODE;
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerLoadServiceImpl.java

protected void writeMessageEntryLines(Document pdfDoc, List<String[]> messageLines) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL);

    Paragraph paragraph;/*from   w  w  w  .j  a v a 2 s  .  c o m*/
    String messageEntry;
    for (String[] messageLine : messageLines) {
        paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_LEFT);
        messageEntry = StringUtils.rightPad(messageLine[0], (12 - messageLine[0].length()), " ") + " - "
                + messageLine[1].toUpperCase();
        paragraph.add(new Chunk(messageEntry, font));

        //  blank line
        paragraph.add(new Chunk("", font));

        try {
            pdfDoc.add(paragraph);
        } catch (DocumentException e) {
            LOG.error("iText DocumentException thrown when trying to write content.", e);
            throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
        }
    }
}

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 w  w  w.  j  a  va2s . 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.cam.batch.service.impl.AssetBarcodeInventoryLoadServiceImpl.java

/**
 * This method invokes the rules in order to validate each records of the barcode file and invokes the method that updates the
 * asset table with the records that passes the rules validation
 * /*from www  .  ja  v  a2 s .  c o m*/
 * @param barcodeInventoryErrorDetails
 */
protected void processBarcodeInventory(List<BarcodeInventoryErrorDetail> barcodeInventoryErrorDetails,
        AssetBarCodeInventoryInputFileForm form) throws Exception {
    Long lineNumber = new Long(0);
    boolean docCreated = false;
    int errorRecCount = 0;
    int totalRecCount = 0;

    BarcodeInventoryErrorDocument barcodeInventoryErrorDocument = createInvalidBarcodeInventoryDocument(
            barcodeInventoryErrorDetails, form.getUploadDescription());
    // apply rules for the new cash control detail
    kualiRuleService.applyRules(new ValidateBarcodeInventoryEvent("", barcodeInventoryErrorDocument, true));

    List<BarcodeInventoryErrorDetail> tmpBarcodeInventoryErrorDetails = new ArrayList<BarcodeInventoryErrorDetail>();

    for (BarcodeInventoryErrorDetail barcodeInventoryErrorDetail : barcodeInventoryErrorDetails) {
        totalRecCount++;
        // if no error found, then update asset table.
        if (!barcodeInventoryErrorDetail.getErrorCorrectionStatusCode()
                .equals(CamsConstants.BarCodeInventoryError.STATUS_CODE_ERROR)) {
            this.updateAssetInformation(barcodeInventoryErrorDetail, true);
        } else {
            errorRecCount++;
            lineNumber++;
            // Assigning the row number to each invalid BCIE record
            barcodeInventoryErrorDetail.setUploadRowNumber(lineNumber);

            // Storing in temp collection the invalid BCIE records.
            tmpBarcodeInventoryErrorDetails.add(barcodeInventoryErrorDetail);
        }
    }
    // *********************************************************************
    // Storing the invalid barcode inventory records.
    // *********************************************************************
    String documentsCreated = "";
    if (!tmpBarcodeInventoryErrorDetails.isEmpty()) {
        documentsCreated = this.createBarcodeInventoryErrorDocuments(tmpBarcodeInventoryErrorDetails,
                barcodeInventoryErrorDocument, form);
        docCreated = true;
    }

    if (!docCreated) {
        form.getMessages().add(MESSAGE_NO_DOCUMENT_CREATED);
    } else {
        // Adding the list of documents that were created in the message list
        form.getMessages().add(DOCUMENTS_MSG + ": " + documentsCreated.substring(2));
    }
    form.getMessages().add(
            TOTAL_RECORDS_UPLOADED_MSG + ": " + StringUtils.rightPad(Integer.toString(totalRecCount), 5, " "));
    form.getMessages().add(
            TOTAL_RECORDS_IN_ERROR_MSG + ": " + StringUtils.rightPad(Integer.toString(errorRecCount), 5, " "));
}

From source file:org.kuali.kfs.module.cam.batch.service.impl.AssetBarcodeInventoryLoadServiceImpl.java

private boolean validateDate(String date) {
    // Parsing date so it can be validated.
    boolean valid = true;
    if (StringHelper.isEmpty(date)) {
        valid = false;/*from  ww  w  . ja va 2  s  .  c o  m*/
    } else {
        SimpleDateFormat formatter = new SimpleDateFormat(
                CamsConstants.DateFormats.MONTH_DAY_YEAR + " " + CamsConstants.DateFormats.STANDARD_TIME,
                Locale.US);
        date = StringUtils.rightPad(date.trim(), 14, "0");
        String day = date.substring(0, 2);
        String month = date.substring(2, 4);
        String year = date.substring(4, 8);
        String hours = date.substring(8, 10);
        String minutes = date.substring(10, 12);
        String seconds = date.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) {
            valid = false;
        }

    }

    return valid;
}

From source file:org.kuali.kfs.module.endow.batch.service.impl.GeneralLedgerInterfaceBatchProcessServiceImpl.java

/**
 * get the separator line - to write a header line in statistics report
 * @return the separator line/*  www  . j  a  v  a 2s  .  co m*/
 */
public String getSepartorLine() {
    int attributeLength = 0;
    StringBuffer separatorLine = new StringBuffer();
    GLInterfaceBatchTotalsProcessedReportHeader reportHeader = new GLInterfaceBatchTotalsProcessedReportHeader();

    attributeLength += reportHeader.getColumn1MaxLength();
    attributeLength += reportHeader.getColumn2MaxLength();
    attributeLength += reportHeader.getColumn3MaxLength();
    separatorLine = separatorLine.append(StringUtils.rightPad(StringUtils.EMPTY, attributeLength, " "))
            .append("   ");
    attributeLength = reportHeader.getColumn4MaxLength();
    separatorLine = separatorLine
            .append(StringUtils.rightPad(StringUtils.EMPTY, attributeLength, KFSConstants.DASH)).append(" ");
    attributeLength = reportHeader.getColumn5MaxLength();
    separatorLine = separatorLine
            .append(StringUtils.rightPad(StringUtils.EMPTY, attributeLength, KFSConstants.DASH)).append(" ");
    attributeLength = reportHeader.getColumn6MaxLength();
    separatorLine = separatorLine
            .append(StringUtils.rightPad(StringUtils.EMPTY, attributeLength, KFSConstants.DASH)).append(" ");

    return separatorLine.toString();
}

From source file:org.kuali.kfs.module.ld.businessobject.LaborOriginEntry.java

/**
 * Get lines from string/*from   w  w w. j a  v  a 2s  .c om*/
 */
@Override
public String getLine() {
    StringBuilder sb = new StringBuilder();
    Map<String, Integer> lMap = getLaborOriginEntryFieldUtil().getFieldLengthMap();
    Map<String, Integer> pMap = getLaborOriginEntryFieldUtil().getFieldBeginningPositionMap();
    int entryLength = pMap.get(LaborPropertyConstants.SET_ID) + lMap.get(LaborPropertyConstants.SET_ID);

    if (universityFiscalYear == null) {
        sb.append(GeneralLedgerConstants.getSpaceUniversityFiscalYear());
    } else {
        sb.append(universityFiscalYear);
    }

    sb.append(getField(lMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE), chartOfAccountsCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.ACCOUNT_NUMBER), accountNumber));
    sb.append(getField(lMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER), subAccountNumber));
    sb.append(getField(lMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE), financialObjectCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE), financialSubObjectCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE), financialBalanceTypeCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE), financialObjectTypeCode));
    sb.append(
            getField(lMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE), universityFiscalPeriodCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE), financialDocumentTypeCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE),
            financialSystemOriginationCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.DOCUMENT_NUMBER), documentNumber));

    String seqNum = "";
    if (transactionLedgerEntrySequenceNumber != null) {
        seqNum = transactionLedgerEntrySequenceNumber.toString();
    }
    // Format to a length of 5
    sb.append(StringUtils.leftPad(seqNum.trim(),
            lMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER), "0"));

    // Labor Specified fields
    sb.append(getField(lMap.get(KFSPropertyConstants.POSITION_NUMBER), positionNumber));
    sb.append(getField(lMap.get(KFSPropertyConstants.PROJECT_CODE), projectCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC),
            transactionLedgerEntryDescription));

    if (transactionLedgerEntryAmount == null) {
        sb.append(GeneralLedgerConstants.getZeroTransactionLedgerEntryAmount());
    } else {
        String a = transactionLedgerEntryAmount.abs().toString();
        if (transactionLedgerEntryAmount.isNegative()) {
            sb.append("-");
        } else {
            sb.append("+");
        }
        sb.append(GeneralLedgerConstants.getZeroTransactionLedgerEntryAmount().substring(1,
                lMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT) - a.length()));
        sb.append(a);
    }

    sb.append(
            getField(lMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE), transactionDebitCreditCode));
    sb.append(formatDate(transactionDate));
    sb.append(
            getField(lMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER), organizationDocumentNumber));
    sb.append(getField(lMap.get(KFSPropertyConstants.ORGANIZATION_REFERENCE_ID), organizationReferenceId));
    sb.append(getField(lMap.get(KFSPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE),
            referenceFinancialDocumentTypeCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE),
            referenceFinancialSystemOriginationCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR),
            referenceFinancialDocumentNumber));
    sb.append(formatDate(financialDocumentReversalDate));
    sb.append(getField(lMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD),
            transactionEncumbranceUpdateCode));
    sb.append(formatDate(transactionPostingDate));
    sb.append(formatDate(payPeriodEndDate));

    if (transactionTotalHours == null) {
        sb.append(StringUtils.rightPad("", lMap.get(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS), " "));
    } else {
        String totalhour = getField(lMap.get(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS),
                transactionTotalHours.toString());
        sb.append(StringUtils.leftPad(totalhour.trim(), lMap.get(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS),
                " "));
    }

    if (payrollEndDateFiscalYear == null) {
        sb.append(StringUtils.rightPad("", lMap.get(KFSPropertyConstants.PAYROLL_END_DATE_FISCAL_YEAR), " "));
    } else {
        sb.append(getField(lMap.get(KFSPropertyConstants.PAYROLL_END_DATE_FISCAL_YEAR),
                payrollEndDateFiscalYear.toString()));
    }

    sb.append(getField(lMap.get(LaborPropertyConstants.PAYROLL_END_DATE_FISCAL_PERIOD_CODE),
            payrollEndDateFiscalPeriodCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.EMPLID), emplid));

    if (employeeRecord == null) {
        sb.append(StringUtils.rightPad("", lMap.get(KFSPropertyConstants.EMPLOYEE_RECORD), " "));
    } else {
        String empRecord = getField(lMap.get(KFSPropertyConstants.EMPLOYEE_RECORD), employeeRecord.toString());
        sb.append(StringUtils.leftPad(empRecord.trim(), lMap.get(KFSPropertyConstants.EMPLOYEE_RECORD), " "));
    }

    sb.append(getField(lMap.get(KFSPropertyConstants.EARN_CODE), earnCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.PAY_GROUP), payGroup));
    sb.append(getField(lMap.get(LaborPropertyConstants.SALARY_ADMINISTRATION_PLAN), salaryAdministrationPlan));
    sb.append(getField(lMap.get(LaborPropertyConstants.GRADE), grade));
    sb.append(getField(lMap.get(LaborPropertyConstants.RUN_IDENTIFIER), runIdentifier));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_CHART_OF_ACCOUNTS_CODE),
            laborLedgerOriginalChartOfAccountsCode));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_ACCOUNT_NUMBER),
            laborLedgerOriginalAccountNumber));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_SUB_ACCOUNT_NUMBER),
            laborLedgerOriginalSubAccountNumber));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_OBJECT_CODE),
            laborLedgerOriginalFinancialObjectCode));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_SUB_OBJECT_CODE),
            laborLedgerOriginalFinancialSubObjectCode));
    sb.append(getField(lMap.get(LaborPropertyConstants.HRMS_COMPANY), hrmsCompany));
    sb.append(getField(lMap.get(LaborPropertyConstants.SET_ID), setid));

    // pad to full length of 295 chars.
    while (entryLength > sb.toString().length()) {
        sb.append(' ');
    }

    // KFSMI-5958: Don't want any control characters in output files. They potentially disrupt further processing
    Matcher controlCharacterMatcher = MATCH_CONTROL_CHARACTERS.matcher(sb);
    String returnString = controlCharacterMatcher.replaceAll(REPLACE_MATCHED_CONTROL_CHARACTERS);

    return returnString;
}

From source file:org.kuali.kfs.module.ld.LaborConstants.java

public static String getSpaceTransactionDate() {
    if (SPACE_TRANSACTION_DATE == null) {
        SPACE_TRANSACTION_DATE = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class)
                .getAttributeSize(OriginEntryFull.class, KFSPropertyConstants.TRANSACTION_DATE), ' ');
    }//from  w  ww  .ja va 2s.co m
    return SPACE_TRANSACTION_DATE;
}

From source file:org.kuali.kfs.module.ld.LaborConstants.java

public static String getDashPositionNumber() {
    if (DASH_POSITION_NUMBER == null) {
        DASH_POSITION_NUMBER = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class)
                .getAttributeMaxLength(LaborOriginEntry.class, KFSPropertyConstants.POSITION_NUMBER), '-');
    }/*from  w ww . j  ava 2 s . c om*/
    return DASH_POSITION_NUMBER;
}

From source file:org.kuali.kfs.module.ld.LaborConstants.java

public static String getDashEmplId() {
    if (DASH_EMPLID == null) {
        DASH_EMPLID = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class)
                .getAttributeMaxLength(LaborOriginEntry.class, KFSPropertyConstants.EMPLID), '-');
    }//from   ww  w  . java  2 s  .co m
    return DASH_EMPLID;
}