List of usage examples for org.apache.commons.lang StringUtils leftPad
public static String leftPad(String str, int size, String padStr)
Left pad a String with a specified String.
From source file:org.jbpm.instance.migration.MigrationUtils.java
/** * The method joins a base Class name and a revision number. It will pad the revision number if necessary. * @param baseClassName//from www . j a va2 s . c o m * @param revision * @return */ private static String constructMigrationClassName(String baseClassName, int revision) { return baseClassName + StringUtils.leftPad(Integer.toString(revision), 3, "0"); }
From source file:org.jspare.server.transaction.TidGeneratorImpl.java
@Override public String generate() { StringBuilder tid = new StringBuilder(); tid.append(LocalDateTime.now().format(dtf)); tid.append(StringUtils.leftPad(String.valueOf(ThreadLocalRandom.current().nextLong(MIN, MAX)), 6, "0")); tid.append(calculateVerifyDigit(tid.toString())); return tid.toString(); }
From source file:org.jumpmind.metl.core.runtime.component.ModelAttributeScriptHelper.java
public String lpad(String padChar, int length) { String text = value != null ? value.toString() : ""; return StringUtils.leftPad(text, length, padChar); }
From source file:org.jumpmind.symmetric.io.stage.StagingManager.java
protected String buildFilePath(Object... path) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < path.length; i++) { Object part = path[i];//from w ww.j a v a 2 s .co m if (part instanceof Number) { part = StringUtils.leftPad(part.toString(), 10, "0"); } buffer.append(part); if (i < path.length - 1) { buffer.append("/"); } } return buffer.toString(); }
From source file:org.kuali.kfs.coa.identity.OrganizationHierarchyAwareRoleTypeServiceBase.java
@Override public List<RoleMembership> sortRoleMembers(List<RoleMembership> roleMembers) { List<SortableRoleMembershipHolder> listToSort = new ArrayList<SortableRoleMembershipHolder>( roleMembers.size());//from ww w . jav a 2 s . com // build the sortable list for (RoleMembership rmi : roleMembers) { listToSort.add(new SortableRoleMembershipHolder(rmi)); } // sort it Collections.sort(listToSort); // restore them to the list in their sorted order List<RoleMembership> newRoleMembers = new ArrayList<RoleMembership>(); // need a new list, because roleMembers is not mutable int group = 0; // counter for the group number to add to the roleSortingCode String lastRoleSortingCode = ""; for (SortableRoleMembershipHolder srmh : listToSort) { if (!srmh.rmi.getRoleSortingCode().equals(lastRoleSortingCode)) { group++; lastRoleSortingCode = srmh.rmi.getRoleSortingCode(); } Builder builder = RoleMembership.Builder.create(srmh.rmi); builder.setRoleSortingCode( StringUtils.leftPad(Integer.toString(group), 3, '0') + "/" + srmh.rmi.getRoleSortingCode()); newRoleMembers.add(builder.build()); } return newRoleMembers; }
From source file:org.kuali.kfs.gl.batch.service.impl.CollectorReportServiceImpl.java
/** * Appends the validation status message to a buffer * * @param buf a StringBuilder to append error messages to * @param errorMessages a List of error messages encountered in the Collector process * @param notifyIfSuccessful true if a special message for the process running successfully should be added, false otherwise * @param numLeftPaddingSpaces the number of spaces to pad on the left *//*from ww w . j a v a 2 s . co m*/ protected void appendValidationStatus(StringBuilder buf, List<String> errorMessages, boolean notifyIfSuccessful, int numLeftPaddingSpaces) { String padding = StringUtils.leftPad("", numLeftPaddingSpaces, ' '); if (notifyIfSuccessful || !errorMessages.isEmpty()) { buf.append("\n").append(padding).append("Reported Errors:\n"); } // ERRORS GO HERE if (errorMessages.isEmpty() && notifyIfSuccessful) { buf.append(padding).append( "----- NO ERRORS TO REPORT -----\nThis file will be processed by the accounting cycle.\n"); } else if (!errorMessages.isEmpty()) { for (String currentMessage : errorMessages) { buf.append(padding).append(currentMessage + "\n"); } buf.append("\n").append(padding).append( "----- THIS FILE WAS NOT PROCESSED AND WILL NEED TO BE CORRECTED AND RESUBMITTED -----\n"); } }
From source file:org.kuali.kfs.gl.businessobject.OriginEntryFull.java
@Override public String getLine() { StringBuffer sb = new StringBuffer(); Map<String, Integer> fieldLengthMap = getOriginEntryFieldUtil().getFieldLengthMap(); if (universityFiscalYear == null) { sb.append(GeneralLedgerConstants.getSpaceUniversityFiscalYear()); } else {//from w w w .j a va 2 s. c o m sb.append(universityFiscalYear); } sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE), chartOfAccountsCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.ACCOUNT_NUMBER), accountNumber)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER), subAccountNumber)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE), financialObjectCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE), financialSubObjectCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE), financialBalanceTypeCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE), financialObjectTypeCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE), universityFiscalPeriodCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE), financialDocumentTypeCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE), financialSystemOriginationCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.DOCUMENT_NUMBER), documentNumber)); // This is the cobol code for transaction sequence numbers. // 3025 019280 IF TRN-ENTR-SEQ-NBR OF GLEN-RECORD NOT NUMERIC // 3026 019290 MOVE ZEROES TO TRN-ENTR-SEQ-NBR OF GLEN-RECORD // 3027 019300 END-IF // 3028 019310 IF TRN-ENTR-SEQ-NBR OF GLEN-RECORD = SPACES // 3029 019320 MOVE ZEROES // 3030 019330 TO TRN-ENTR-SEQ-NBR OF ALT-GLEN-RECORD // 3031 019340 ELSE // 3032 019350 MOVE TRN-ENTR-SEQ-NBR OF GLEN-RECORD // 3033 019360 TO TRN-ENTR-SEQ-NBR OF ALT-GLEN-RECORD // 3034 019370 END-IF String seqNum = ""; if (transactionLedgerEntrySequenceNumber != null) { seqNum = transactionLedgerEntrySequenceNumber.toString(); } // Format to a length of 5 sb.append(StringUtils.leftPad(seqNum.trim(), fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER), "0")); sb.append(getField(fieldLengthMap.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, fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT) - a.length())); sb.append(a); } sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE), transactionDebitCreditCode)); sb.append(formatDate(transactionDate)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER), organizationDocumentNumber)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.PROJECT_CODE), projectCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.ORGANIZATION_REFERENCE_ID), organizationReferenceId)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE), referenceFinancialDocumentTypeCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE), referenceFinancialSystemOriginationCode)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR), referenceFinancialDocumentNumber)); sb.append(formatDate(financialDocumentReversalDate)); sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD), transactionEncumbranceUpdateCode)); // pad to full length while (GeneralLedgerConstants.getSpaceAllOriginEntryFields().length() > 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.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 . ja v a2 s . c om*/ */ 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.ar.report.service.impl.OCRLineServiceImpl.java
/** * @see org.kuali.kfs.module.ar.report.service.OCRLineService#generateOCRL(java.lang.String, java.lang.String) *///from ww w.ja va 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.cam.batch.service.impl.AssetDepreciationServiceImpl.java
/** * This method stores the depreciation transactions in the general pending entry table and creates a new documentHeader entry. * <p>// w w w . j av a 2 s. c o m * * @param trans SortedMap with the transactions * @return none */ protected void processGeneralLedgerPendingEntry(Integer fiscalYear, Integer fiscalMonth, List<String> documentNos, SortedMap<String, AssetDepreciationTransaction> trans) { LOG.debug( "populateExplicitGeneralLedgerPendingEntry(AccountingDocument, AccountingLine, GeneralLedgerPendingEntrySequenceHelper, GeneralLedgerPendingEntry) - start"); String financialSystemDocumentTypeCodeCode; try { String documentNumber = createNewDepreciationDocument(documentNos); financialSystemDocumentTypeCodeCode = CamsConstants.DocumentTypeName.ASSET_DEPRECIATION; LOG.debug(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Depreciation Document Type Code: " + financialSystemDocumentTypeCodeCode); Timestamp transactionTimestamp = new Timestamp(dateTimeService.getCurrentDate().getTime()); GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(); List<GeneralLedgerPendingEntry> saveList = new ArrayList<GeneralLedgerPendingEntry>(); int counter = 0; for (AssetDepreciationTransaction t : trans.values()) { if (t.getTransactionAmount().isNonZero()) { counter++; LOG.debug(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Creating GLPE entries for asset:" + t.getCapitalAssetNumber()); GeneralLedgerPendingEntry explicitEntry = new GeneralLedgerPendingEntry(); explicitEntry.setFinancialSystemOriginationCode(KFSConstants.ORIGIN_CODE_KUALI); explicitEntry.setDocumentNumber(documentNumber); explicitEntry.setTransactionLedgerEntrySequenceNumber( new Integer(sequenceHelper.getSequenceCounter())); sequenceHelper.increment(); explicitEntry.setChartOfAccountsCode(t.getChartOfAccountsCode()); explicitEntry.setAccountNumber(t.getAccountNumber()); explicitEntry.setSubAccountNumber(null); explicitEntry.setFinancialObjectCode(t.getFinancialObjectCode()); explicitEntry.setFinancialSubObjectCode(null); explicitEntry.setFinancialBalanceTypeCode(BALANCE_TYPE_ACTUAL); explicitEntry.setFinancialObjectTypeCode(t.getFinancialObjectTypeCode()); explicitEntry.setUniversityFiscalYear(fiscalYear); explicitEntry.setUniversityFiscalPeriodCode( StringUtils.leftPad(fiscalMonth.toString().trim(), 2, "0")); explicitEntry.setTransactionLedgerEntryDescription(t.getTransactionLedgerEntryDescription()); explicitEntry.setTransactionLedgerEntryAmount(t.getTransactionAmount().abs()); explicitEntry.setTransactionDebitCreditCode(t.getTransactionType()); explicitEntry.setTransactionDate(new java.sql.Date(transactionTimestamp.getTime())); explicitEntry.setFinancialDocumentTypeCode(financialSystemDocumentTypeCodeCode); explicitEntry.setFinancialDocumentApprovedCode(KFSConstants.DocumentStatusCodes.APPROVED); explicitEntry.setVersionNumber(new Long(1)); explicitEntry .setTransactionEntryProcessedTs(new java.sql.Timestamp(transactionTimestamp.getTime())); // this.generalLedgerPendingEntryService.save(explicitEntry); saveList.add(explicitEntry); if (counter % 1000 == 0) { // save here getDepreciationBatchDao().savePendingGLEntries(saveList); saveList.clear(); } if (sequenceHelper.getSequenceCounter() == 99999) { // create new document and sequence is reset documentNumber = createNewDepreciationDocument(documentNos); sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(); } } } // save last list getDepreciationBatchDao().savePendingGLEntries(saveList); saveList.clear(); } catch (Exception e) { LOG.error("Error occurred", e); throw new IllegalStateException(kualiConfigurationService.getPropertyValueAsString( CamsKeyConstants.Depreciation.ERROR_WHEN_UPDATING_GL_PENDING_ENTRY_TABLE) + " :" + e.getMessage()); } LOG.debug( "populateExplicitGeneralLedgerPendingEntry(AccountingDocument, AccountingLine, GeneralLedgerPendingEntrySequenceHelper, GeneralLedgerPendingEntry) - end"); }