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);
}
}
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);
}
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;
}
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();
}
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;
}
Aggregations