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

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

Introduction

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

Prototype

public static String left(String str, int len) 

Source Link

Document

Gets the leftmost len characters of a String.

Usage

From source file:org.kuali.kfs.module.cam.document.AssetGlobalMaintainableImpl.java

/**
 * @see org.kuali.rice.kns.maintenance.KualiGlobalMaintainableImpl#prepareForSave()
 *///from  w ww  . j  ava  2s  .  c  o m
@Override
public void prepareForSave() {
    super.prepareForSave();
    AssetGlobal assetGlobal = (AssetGlobal) this.getBusinessObject();

    //we need to set the posting period and posting year from the value of the drop-down box...
    if (StringUtils.isNotBlank(assetGlobal.getUniversityFiscalPeriodName())) {
        assetGlobal.setFinancialDocumentPostingPeriodCode(
                StringUtils.left(assetGlobal.getUniversityFiscalPeriodName(), 2));
        assetGlobal.setFinancialDocumentPostingYear(
                new Integer(StringUtils.right(assetGlobal.getUniversityFiscalPeriodName(), 4)));
    }

    List<AssetGlobalDetail> assetSharedDetails = assetGlobal.getAssetSharedDetails();
    List<AssetGlobalDetail> newDetails = new ArrayList<AssetGlobalDetail>();
    AssetGlobalDetail newAssetGlobalDetail = null;
    if (!assetSharedDetails.isEmpty() && !assetSharedDetails.get(0).getAssetGlobalUniqueDetails().isEmpty()) {

        for (AssetGlobalDetail locationDetail : assetSharedDetails) {
            List<AssetGlobalDetail> assetGlobalUniqueDetails = locationDetail.getAssetGlobalUniqueDetails();

            for (AssetGlobalDetail detail : assetGlobalUniqueDetails) {
                // read from location and set it to detail
                if (ObjectUtils.isNotNull(locationDetail.getCampusCode())) {
                    detail.setCampusCode(locationDetail.getCampusCode().toUpperCase());
                } else {
                    detail.setCampusCode(locationDetail.getCampusCode());
                }
                if (ObjectUtils.isNotNull(locationDetail.getBuildingCode())) {
                    detail.setBuildingCode(locationDetail.getBuildingCode().toUpperCase());
                } else {
                    detail.setBuildingCode(locationDetail.getBuildingCode());
                }
                detail.setBuildingRoomNumber(locationDetail.getBuildingRoomNumber());
                detail.setBuildingSubRoomNumber(locationDetail.getBuildingSubRoomNumber());
                detail.setOffCampusName(locationDetail.getOffCampusName());
                detail.setOffCampusAddress(locationDetail.getOffCampusAddress());
                detail.setOffCampusCityName(locationDetail.getOffCampusCityName());
                detail.setOffCampusStateCode(locationDetail.getOffCampusStateCode());
                detail.setOffCampusCountryCode(locationDetail.getOffCampusCountryCode());
                detail.setOffCampusZipCode(locationDetail.getOffCampusZipCode());
                newDetails.add(detail);
            }
        }
    }

    if (assetGlobal.getCapitalAssetTypeCode() != null) {
        assetGlobal.refreshReferenceObject(CamsPropertyConstants.AssetGlobal.CAPITAL_ASSET_TYPE);
        AssetType capitalAssetType = assetGlobal.getCapitalAssetType();
        if (ObjectUtils.isNotNull(capitalAssetType)) {
            if (capitalAssetType.getDepreciableLifeLimit() != null
                    && capitalAssetType.getDepreciableLifeLimit().intValue() != 0) {
                assetGlobal.setCapitalAssetInServiceDate(
                        assetGlobal.getCreateDate() == null ? getDateTimeService().getCurrentSqlDate()
                                : assetGlobal.getCreateDate());
            } else {
                assetGlobal.setCapitalAssetInServiceDate(null);
            }
            computeDepreciationDate(assetGlobal);
            // CSU 6702 BEGIN
            doPeriod13Changes(assetGlobal);
            // CSU 6702 END
        }
    }
    assetGlobal.getAssetGlobalDetails().clear();
    assetGlobal.getAssetGlobalDetails().addAll(newDetails);
}

From source file:org.kuali.kfs.module.cam.document.AssetPaymentDocument.java

/**
 * @see org.kuali.kfs.sys.document.AccountingDocumentBase#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
 */// ww w.  j  a v a2 s.  co m
@Override
public void prepareForSave(KualiDocumentEvent event) {
    // This method  prevents kuali from generating a
    // gl pending entry record.

    for (AssetPaymentAssetDetail assetDetail : this.getAssetPaymentAssetDetail()) {
        assetDetail.refreshReferenceObject(CamsPropertyConstants.AssetPaymentAssetDetail.ASSET);
        if (ObjectUtils.isNotNull(assetDetail.getAsset())
                && assetDetail.getAsset().getTotalCostAmount() != null) {
            assetDetail.setPreviousTotalCostAmount(assetDetail.getAsset().getTotalCostAmount());
        }
        // CSU 6702 BEGIN Inferred change 
        List<AssetPaymentDetail> apdList = assetDetail.getAssetPaymentDetails();
        for (AssetPaymentDetail apd : apdList) {
            String accountingPeriodCompositeString = getAccountingPeriodCompositeString();
            apd.setPostingYear(new Integer(StringUtils.right(accountingPeriodCompositeString, 4)));
            apd.setPostingPeriodCode(StringUtils.left(accountingPeriodCompositeString, 2));
        }
        // CSU 6702 END Inferred change            
    }
}

From source file:org.kuali.kfs.module.cam.document.AssetTransferDocument.java

/**
 * KSMI-6702 FY End change//from w  w w.ja va2s  . co m
 * @see org.kuali.kfs.sys.document.GeneralLedgerPostingDocumentBase#prepareForSave(org.kuali.rice.kns.rule.event.KualiDocumentEvent)
 */
@Override
public void prepareForSave(KualiDocumentEvent event) {
    super.prepareForSave(event);
    String accountingPeriodCompositeString = getAccountingPeriodCompositeString();
    setPostingYear(new Integer(StringUtils.right(accountingPeriodCompositeString, 4)));
    setPostingPeriodCode(StringUtils.left(accountingPeriodCompositeString, 2));
}

From source file:org.kuali.kfs.module.cam.document.validation.impl.AssetGlobalRule.java

@Override
protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
    AssetGlobal assetGlobal = (AssetGlobal) document.getNewMaintainableObject().getBusinessObject();
    boolean success = true;
    success &= super.processCustomSaveDocumentBusinessRules(document);
    if (GlobalVariables.getMessageMap().hasErrors()) {
        return false;
    }//ww  w  .  j  a va  2 s.co  m

    String acquisitionTypeCode = assetGlobal.getAcquisitionTypeCode();
    String statusCode = assetGlobal.getInventoryStatusCode();

    // no need to validate specific fields if document is "Asset Separate"
    if (!getAssetGlobalService().isAssetSeparate(assetGlobal)) {
        success &= validateAccount(assetGlobal);
        if (StringUtils.isNotBlank(acquisitionTypeCode) && StringUtils.isNotBlank(statusCode)) {
            // check if status code and acquisition type code combination is valid
            success &= /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class)
                    .getParameterEvaluator(AssetGlobal.class,
                            CamsConstants.Parameters.VALID_ASSET_STATUSES_BY_ACQUISITION_TYPE,
                            CamsConstants.Parameters.INVALID_ASSET_STATUSES_BY_ACQUISITION_TYPE,
                            acquisitionTypeCode, statusCode)
                    .evaluateAndAddError(AssetGlobal.class,
                            CamsPropertyConstants.AssetGlobal.INVENTORY_STATUS_CODE, MAINTAINABLE_ERROR_PREFIX
                                    + CamsPropertyConstants.AssetGlobal.INVENTORY_STATUS_CODE);
        }
        success &= validateAssetType(assetGlobal);
        if (isCapitalStatus(assetGlobal)) {
            success &= validateVendorAndManufacturer(assetGlobal);
        }

        success &= validatePaymentCollection(document, assetGlobal);
    } else {
        // append doc type to existing doc header description
        if (!document.getDocumentHeader().getDocumentDescription().toLowerCase()
                .contains(CamsConstants.AssetSeparate.SEPARATE_AN_ASSET_DESCRIPTION.toLowerCase())) {
            Integer maxDocumentDescription = ddService.getAttributeMaxLength(DocumentHeader.class,
                    KRADPropertyConstants.DOCUMENT_DESCRIPTION);
            String documentDescription = CamsConstants.AssetSeparate.SEPARATE_AN_ASSET_DESCRIPTION + " "
                    + document.getDocumentHeader().getDocumentDescription();
            documentDescription = StringUtils.left(documentDescription, maxDocumentDescription);
            document.getDocumentHeader().setDocumentDescription(documentDescription);
        }
    }

    // System shall only generate GL entries if we have an incomeAssetObjectCode for this acquisitionTypeCode and the statusCode
    // is for capital assets
    //  GLs should not be generated while separating assets too
    if ((success && !getAssetGlobalService().isAssetSeparate(assetGlobal)
            && super.processCustomSaveDocumentBusinessRules(document))
            && getAssetAcquisitionTypeService().hasIncomeAssetObjectCode(acquisitionTypeCode)
            && this.isCapitalStatus(assetGlobal)) {
        if (success &= validateAcquisitionIncomeObjectCode(assetGlobal)) {
            // create poster
            AssetGlobalGeneralLedgerPendingEntrySource assetGlobalGlPoster = new AssetGlobalGeneralLedgerPendingEntrySource(
                    (FinancialSystemDocumentHeader) document.getDocumentHeader());
            // create postables
            getAssetGlobalService().createGLPostables(assetGlobal, assetGlobalGlPoster);

            if (SpringContext.getBean(GeneralLedgerPendingEntryService.class)
                    .generateGeneralLedgerPendingEntries(assetGlobalGlPoster)) {
                assetGlobal.setGeneralLedgerPendingEntries(assetGlobalGlPoster.getPendingEntries());
            } else {
                assetGlobalGlPoster.getPendingEntries().clear();
            }
        }
    }

    return success;
}

From source file:org.kuali.kfs.module.cam.document.validation.impl.AssetRetirementGlobalRule.java

/**
 * Processes rules when saving this global.
 *
 * @param document MaintenanceDocument type of document to be processed.
 * @return boolean true when success//from  w  w w.  ja  v a2s  . c o  m
 * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
 */
@Override
protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
    boolean valid = true;
    AssetRetirementGlobal assetRetirementGlobal = (AssetRetirementGlobal) document.getNewMaintainableObject()
            .getBusinessObject();

    setupConvenienceObjects();
    valid &= assetRetirementValidation(assetRetirementGlobal, document);

    if ((valid && super.processCustomSaveDocumentBusinessRules(document))
            && !getAssetRetirementService().isAssetRetiredByMerged(assetRetirementGlobal)
            && !allPaymentsFederalOwned(assetRetirementGlobal)) {
        // Check if Asset Object Code and Object code exists and active.
        if (valid &= validateObjectCodesForGLPosting(assetRetirementGlobal)) {
            // create poster
            AssetRetirementGeneralLedgerPendingEntrySource assetRetirementGlPoster = new AssetRetirementGeneralLedgerPendingEntrySource(
                    (FinancialSystemDocumentHeader) document.getDocumentHeader());
            // create postables
            getAssetRetirementService().createGLPostables(assetRetirementGlobal, assetRetirementGlPoster);

            if (SpringContext.getBean(GeneralLedgerPendingEntryService.class)
                    .generateGeneralLedgerPendingEntries(assetRetirementGlPoster)) {
                assetRetirementGlobal
                        .setGeneralLedgerPendingEntries(assetRetirementGlPoster.getPendingEntries());
            } else {
                assetRetirementGlPoster.getPendingEntries().clear();
            }
        }
    }

    // add doc header description if retirement reason is "MERGED"
    if (CamsConstants.AssetRetirementReasonCode.MERGED
            .equals(assetRetirementGlobal.getRetirementReasonCode())) {
        if (!document.getDocumentHeader().getDocumentDescription().toLowerCase()
                .contains(CamsConstants.AssetRetirementGlobal.MERGE_AN_ASSET_DESCRIPTION.toLowerCase())) {
            Integer maxDocumentDescription = ddService.getAttributeMaxLength(DocumentHeader.class,
                    KRADPropertyConstants.DOCUMENT_DESCRIPTION);
            String documentDescription = CamsConstants.AssetRetirementGlobal.MERGE_AN_ASSET_DESCRIPTION + " "
                    + document.getDocumentHeader().getDocumentDescription();
            documentDescription = StringUtils.left(documentDescription, maxDocumentDescription);
            document.getDocumentHeader().setDocumentDescription(documentDescription);
        }
    }
    // get asset locks
    List<Long> capitalAssetNumbers = retrieveAssetNumbersForLocking(assetRetirementGlobal);
    valid &= !this.getCapitalAssetManagementModuleService().isAssetLocked(capitalAssetNumbers,
            DocumentTypeName.ASSET_RETIREMENT_GLOBAL, document.getDocumentNumber());

    return valid;
}

From source file:org.kuali.kfs.module.ld.service.impl.LaborTransactionDescriptionServiceImpl.java

/**
 * @see org.kuali.kfs.module.ld.service.LaborTransactionDescriptionService#getTransactionDescription(org.kuali.kfs.gl.businessobject.Transaction)
 *///from   w w w  .j  ava2 s  . com
public String getTransactionDescription(Transaction transaction) {
    String documentTypeCode = transaction.getFinancialDocumentTypeCode();
    String description = this.getTransactionDescription(documentTypeCode);
    description = StringUtils.isNotEmpty(description) ? description
            : transaction.getTransactionLedgerEntryDescription();

    // make sure the length of the description cannot excess the specified maximum
    int transactionDescriptionMaxLength = SpringContext.getBean(DataDictionaryService.class)
            .getAttributeMaxLength(transaction.getClass(), KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC);
    if (StringUtils.isNotEmpty(description) && description.length() > transactionDescriptionMaxLength) {
        description = StringUtils.left(description, transactionDescriptionMaxLength);
    }

    return description;
}

From source file:org.kuali.kfs.module.purap.businessobject.options.PurchaseOrderRetransmissionMethodValuesFinder.java

/**
 * Returns code/description pairs of all Purchase Order Retransmission Methods.
 * //w  w w  .j av  a  2  s .  c  o  m
 * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues()
 */
public List<KeyValue> getKeyValues() {
    KeyValuesService boService = SpringContext.getBean(KeyValuesService.class);
    Collection<PurchaseOrderTransmissionMethod> codes = boService
            .findAll(PurchaseOrderTransmissionMethod.class);
    String retransmitTypes = SpringContext.getBean(ParameterService.class).getParameterValueAsString(
            PurchaseOrderDocument.class, PurapParameterConstants.PURAP_PO_RETRANSMIT_TRANSMISSION_METHOD_TYPES);
    List<KeyValue> labels = new ArrayList<KeyValue>();
    if (retransmitTypes != null) {
        for (PurchaseOrderTransmissionMethod purchaseOrderTransmissionMethod : codes) {
            if (StringUtils
                    .contains(retransmitTypes, StringUtils
                            .left(purchaseOrderTransmissionMethod.getPurchaseOrderTransmissionMethodCode(), 4))
                    && purchaseOrderTransmissionMethod.isDisplayToUser()) {
                labels.add(new ConcreteKeyValue(
                        purchaseOrderTransmissionMethod.getPurchaseOrderTransmissionMethodCode(),
                        purchaseOrderTransmissionMethod.getPurchaseOrderTransmissionMethodDescription()));
            }
        }
    }
    return labels;
}

From source file:org.kuali.kfs.module.tem.document.service.impl.TaxableRamificationDocumentServiceImpl.java

/**
 * populate the given tax ramification document with the information provided by the given travel advance
 *//*from   w  w  w.j av a  2s.  c om*/
protected void populateTaxRamificationDocument(TaxableRamificationDocument taxRamificationDocument,
        TravelAdvance travelAdvance) {
    taxRamificationDocument.setArInvoiceDocNumber(travelAdvance.getArInvoiceDocNumber());

    taxRamificationDocument.setTravelAdvanceDocumentNumber(travelAdvance.getDocumentNumber());
    taxRamificationDocument.setTravelAdvance(travelAdvance);

    TravelAuthorizationDocument travelAuthorizationDocument = this
            .getTravelAuthorizationDocument(travelAdvance);
    String travelDocumentIdentifier = travelAuthorizationDocument.getTravelDocumentIdentifier();
    taxRamificationDocument.setTravelDocumentIdentifier(travelDocumentIdentifier);

    TravelerDetail travelerDetail = travelAuthorizationDocument.getTraveler();
    this.refreshTraverler(travelerDetail);
    taxRamificationDocument.setTravelerDetailId(travelerDetail.getId());
    taxRamificationDocument.setTravelerDetail(travelerDetail);

    AccountsReceivableCustomerInvoice customerInvoice = this.getOpenCustomerInvoice(travelAdvance);
    taxRamificationDocument.setOpenAmount(customerInvoice.getOpenAmount());
    taxRamificationDocument.setInvoiceAmount(customerInvoice.getTotalDollarAmount());
    taxRamificationDocument.setDueDate(customerInvoice.getInvoiceDueDate());

    String taxRamificationNotice = this.getNotificationText();
    taxRamificationDocument.setTaxableRamificationNotice(taxRamificationNotice);

    taxRamificationDocument.getDocumentHeader()
            .setOrganizationDocumentNumber(String.valueOf(travelDocumentIdentifier));

    String travelerPrincipalName = StringUtils.upperCase(travelerDetail.getPrincipalName());
    String description = this.getNotificationSubject() + travelerPrincipalName;
    taxRamificationDocument.getDocumentHeader().setDocumentDescription(
            StringUtils.left(description, KFSConstants.getMaxLengthOfDocumentDescription()));
}

From source file:org.kuali.kfs.sys.document.LedgerPostingDocumentBase.java

/**
 * Set accountingPeriod based on incoming paramater.
 * @param accountingPeriodString in the form of [period][year]
 *///from w  w  w .  j a  v a2 s .  c  om
public void setAccountingPeriodCompositeString(String accountingPeriodString) {
    if (StringUtils.isNotBlank(accountingPeriodString)) {
        String period = StringUtils.left(accountingPeriodString, 2);
        Integer year = new Integer(StringUtils.right(accountingPeriodString, 4));
        AccountingPeriod accountingPeriod = getAccountingPeriodService().getByPeriod(period, year);
        setAccountingPeriod(accountingPeriod);
    }
}

From source file:org.kuali.kfs.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, skipLine, true, true);

    List<DebarredVendorDetail> debarredVendors = new ArrayList<DebarredVendorDetail>();
    String[] nextLine;/*from  ww w  .  j  a  v a2  s. c  om*/
    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;
}