Search in sources :

Example 6 with BusinessObject

use of org.kuali.rice.krad.bo.BusinessObject in project cu-kfs by CU-CommunityApps.

the class BusinessObjectFlatFileSerializerServiceBase method writeLines.

protected void writeLines(BufferedWriter writer, BusinessObjectFlatFileSerializerFieldUtils serializerUtils, List<? extends BusinessObject> lineObjects) throws IOException {
    for (BusinessObject lineObject : lineObjects) {
        String line = serializerUtils.serializeBusinessObject(lineObject);
        writer.write(line);
        writer.write(KFSConstants.NEWLINE);
    }
}
Also used : BusinessObject(org.kuali.rice.krad.bo.BusinessObject)

Example 7 with BusinessObject

use of org.kuali.rice.krad.bo.BusinessObject in project cu-kfs by CU-CommunityApps.

the class BusinessObjectFlatFileSerializerFieldUtils method serializeBusinessObject.

/**
 * Takes a business object that is compatible with the configured BO parsing utility object,
 * and serializes it to a fixed-length String based on the utility's metadata and any
 * custom property-serialization Functions that have been configured. Property values
 * will be truncated or right-padded as needed to match the max lengths from the metadata.
 *
 * If the initialize() method has not already been invoked, this method will call it
 * prior to performing the object serialization.
 *
 * @param businessObject The business object to serialize; cannot be null.
 * @return A single-line fixed-width String representation of the given object, intended for being written to an output file.
 * @throws IllegalArgumentException if businessObject is null or is not an instance of the expected type.
 * @throws NullPointerException if thrown by initialize() or if a property-serialization Function converts a property value to a null String.
 */
public String serializeBusinessObject(BusinessObject businessObject) {
    if (ObjectUtils.isNull(businessObject)) {
        throw new IllegalArgumentException("businessObject cannot be null");
    } else if (!parserFieldUtils.getBusinessObjectClass().isAssignableFrom(businessObject.getClass())) {
        throw new IllegalArgumentException("businessObject is not of the expected type");
    } else if (fieldSerializerFunctions == null) {
        initialize();
    }
    Map<String, Integer> fieldLengthMap = parserFieldUtils.getFieldLengthMap();
    StringBuilder outputLine = new StringBuilder(lineLength);
    for (String propertyName : parserFieldUtils.getOrderedProperties()) {
        Object propertyValue = ObjectPropertyUtils.getPropertyValue(businessObject, propertyName);
        int propertyMaxLength = fieldLengthMap.get(propertyName).intValue();
        Function<Object, String> serializerFunction = fieldSerializerFunctions.getOrDefault(propertyName, this::defaultConversionToString);
        String stringValue = serializerFunction.apply(propertyValue);
        if (stringValue == null) {
            throw new NullPointerException("Property was serialized to a null string: " + propertyName);
        }
        stringValue = formatForOutput(stringValue, propertyMaxLength);
        outputLine.append(stringValue);
    }
    String outputString = outputLine.toString();
    return controlCharacterPattern.matcher(outputString).replaceAll(KRADConstants.BLANK_SPACE);
}
Also used : BusinessObject(org.kuali.rice.krad.bo.BusinessObject)

Example 8 with BusinessObject

use of org.kuali.rice.krad.bo.BusinessObject in project cu-kfs by CU-CommunityApps.

the class CuAssetLookupableHelperServiceImpl method excludeBlankOffCampusLocations.

protected List<? extends BusinessObject> excludeBlankOffCampusLocations(List<? extends BusinessObject> results) {
    List<Asset> resultsModified = new ArrayList<Asset>();
    int count = 0;
    LOG.info("Asset count: " + results.size());
    for (BusinessObject boAsset : results) {
        Asset asset;
        if (boAsset instanceof Asset) {
            count++;
            boolean remove = false;
            asset = (Asset) boAsset;
            List<AssetLocation> locs = asset.getAssetLocations();
            if (locs.isEmpty()) {
                resultsModified.add(asset);
            }
            LOG.info("Asset location counts: " + locs.size());
            for (AssetLocation assetLoc : locs) {
                if (StringUtils.equalsIgnoreCase(assetLoc.getAssetLocationTypeCode(), "O")) {
                    remove |= StringUtils.isBlank(assetLoc.getAssetLocationStreetAddress());
                }
            }
            if (!remove) {
                resultsModified.add(asset);
            } else {
                LOG.info("Removing asset: " + asset.getCapitalAssetNumber());
            }
        } else {
            break;
        }
    }
    LOG.info("Assets reviewed: " + count);
    LOG.info("Results returned: " + resultsModified.size());
    return resultsModified;
}
Also used : AssetLocation(org.kuali.kfs.module.cam.businessobject.AssetLocation) ArrayList(java.util.ArrayList) Asset(org.kuali.kfs.module.cam.businessobject.Asset) BusinessObject(org.kuali.rice.krad.bo.BusinessObject)

Example 9 with BusinessObject

use of org.kuali.rice.krad.bo.BusinessObject in project cu-kfs by CU-CommunityApps.

the class BusinessObjectFlatFileSerializerServiceBase method writeToFile.

protected void writeToFile(BufferedWriter writer, BusinessObject objectToSerialize) throws IOException {
    BusinessObject header = getHeader(objectToSerialize);
    List<? extends BusinessObject> lineItems = getLineItems(objectToSerialize);
    BusinessObject footer = getFooter(objectToSerialize);
    if (ObjectUtils.isNotNull(header)) {
        writeLines(writer, headerSerializerUtils, Collections.singletonList(header));
    }
    writeLines(writer, lineItemSerializerUtils, lineItems);
    if (ObjectUtils.isNotNull(footer)) {
        writeLines(writer, footerSerializerUtils, Collections.singletonList(footer));
    }
    writer.flush();
}
Also used : BusinessObject(org.kuali.rice.krad.bo.BusinessObject)

Example 10 with BusinessObject

use of org.kuali.rice.krad.bo.BusinessObject in project cu-kfs by CU-CommunityApps.

the class DisbursementVoucherDocumentBatchServiceImpl method getDisbursementVoucherBatchDefault.

/**
 * Retrieves the setup batch default record for the unit code
 *
 * @param unitCode unit code on batch default record to retrieve
 * @return DisbursementVoucherBatchDefault containing default values for DV
 */
protected DisbursementVoucherBatchDefault getDisbursementVoucherBatchDefault(String unitCode) {
    Map<String, String> pkValues = new HashMap<String, String>();
    pkValues.put(FPPropertyConstants.UNIT_CODE, unitCode);
    BusinessObject batchDefaults = businessObjectService.findByPrimaryKey(DisbursementVoucherBatchDefault.class, pkValues);
    return (DisbursementVoucherBatchDefault) batchDefaults;
}
Also used : HashMap(java.util.HashMap) DisbursementVoucherBatchDefault(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchDefault) BusinessObject(org.kuali.rice.krad.bo.BusinessObject)

Aggregations

BusinessObject (org.kuali.rice.krad.bo.BusinessObject)15 HashMap (java.util.HashMap)9 AbstractPositionDataDetailsInquirableImpl (org.kuali.kfs.integration.ld.businessobject.inquiry.AbstractPositionDataDetailsInquirableImpl)6 AnchorHtmlData (org.kuali.kfs.kns.lookup.HtmlData.AnchorHtmlData)6 PositionDataDetailsInquirableImpl (org.kuali.kfs.module.ld.businessobject.inquiry.PositionDataDetailsInquirableImpl)6 ArrayList (java.util.ArrayList)3 LedgerBalance (org.kuali.kfs.module.ld.businessobject.LedgerBalance)3 LaborCalculatedSalaryFoundationTracker (org.kuali.kfs.module.ld.businessobject.LaborCalculatedSalaryFoundationTracker)2 DisbursementVoucherBatchDefault (com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchDefault)1 CurrentFundsInquirableImpl (com.rsmart.kuali.kfs.module.ld.businessobject.inquiry.CurrentFundsInquirableImpl)1 EmployeeFundingInquirableImpl (com.rsmart.kuali.kfs.module.ld.businessobject.inquiry.EmployeeFundingInquirableImpl)1 July1PositionFundingInquirableImpl (com.rsmart.kuali.kfs.module.ld.businessobject.inquiry.July1PositionFundingInquirableImpl)1 LaborCalculatedSalaryFoundationTrackerInquirableImpl (com.rsmart.kuali.kfs.module.ld.businessobject.inquiry.LaborCalculatedSalaryFoundationTrackerInquirableImpl)1 LedgerBalanceInquirableImpl (com.rsmart.kuali.kfs.module.ld.businessobject.inquiry.LedgerBalanceInquirableImpl)1 PositionFundingInquirableImpl (com.rsmart.kuali.kfs.module.ld.businessobject.inquiry.PositionFundingInquirableImpl)1 CuDisbursementPayee (edu.cornell.kfs.fp.businessobject.CuDisbursementPayee)1 Map (java.util.Map)1 Account (org.kuali.kfs.coa.businessobject.Account)1 DisbursementPayee (org.kuali.kfs.fp.businessobject.DisbursementPayee)1 LookupableHelperService (org.kuali.kfs.kns.lookup.LookupableHelperService)1