use of org.kuali.kfs.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.kfs.krad.bo.BusinessObject in project cu-kfs by CU-CommunityApps.
the class FinancialSystemSearchableAttribute method getSearchingRows.
@Override
protected List<Row> getSearchingRows(String documentTypeName) {
if (LOG.isDebugEnabled()) {
LOG.debug("getSearchingRows( " + documentTypeName + " )");
if (LOG.isTraceEnabled()) {
LOG.trace("Stack Trace at point of call", new Throwable());
}
}
List<Row> docSearchRows = super.getSearchingRows(documentTypeName);
// add account number search field when selected document type is COA
if (StringUtils.isNotEmpty(documentTypeName)) {
if (CUKFSConstants.COA_DOCUMENT_TYPE.equalsIgnoreCase(documentTypeName)) {
Field accountField = FieldUtils.getPropertyField(Account.class, KFSPropertyConstants.ACCOUNT_NUMBER, true);
accountField.setFieldDataType(CoreConstants.DATA_TYPE_STRING);
accountField.setColumnVisible(true);
docSearchRows.add(new Row(Collections.singletonList(accountField)));
}
}
DocumentEntry entry = SpringContext.getBean(DocumentDictionaryService.class).getDocumentEntry(documentTypeName);
if (entry != null) {
Class<? extends Document> docClass = entry.getDocumentClass();
if (AccountingDocument.class.isAssignableFrom(docClass)) {
Map<String, AccountingLineGroupDefinition> alGroups = ((FinancialSystemTransactionalDocumentEntry) entry).getAccountingLineGroups();
Class alClass = SourceAccountingLine.class;
if (ObjectUtils.isNotNull(alGroups)) {
if (alGroups.containsKey("source")) {
alClass = alGroups.get("source").getAccountingLineClass();
}
}
BusinessObject alBusinessObject;
try {
alBusinessObject = (BusinessObject) alClass.newInstance();
} catch (Exception cnfe) {
throw new RuntimeException("Unable to instantiate accounting line class: " + alClass, cnfe);
}
Field chartField = FieldUtils.getPropertyField(alClass, KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, true);
chartField.setFieldDataType(CoreConstants.DATA_TYPE_STRING);
chartField.setColumnVisible(true);
LookupUtils.setFieldQuickfinder(alBusinessObject, KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartField, Collections.singletonList(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE));
docSearchRows.add(new Row(Collections.singletonList(chartField)));
Field orgField = FieldUtils.getPropertyField(Organization.class, KFSPropertyConstants.ORGANIZATION_CODE, true);
orgField.setFieldDataType(CoreConstants.DATA_TYPE_STRING);
orgField.setColumnVisible(true);
LookupUtils.setFieldQuickfinder(new Account(), KFSPropertyConstants.ORGANIZATION_CODE, orgField, Collections.singletonList(KFSPropertyConstants.ORGANIZATION_CODE));
docSearchRows.add(new Row(Collections.singletonList(orgField)));
Field accountField = FieldUtils.getPropertyField(alClass, KFSPropertyConstants.ACCOUNT_NUMBER, true);
accountField.setFieldDataType(CoreConstants.DATA_TYPE_STRING);
accountField.setColumnVisible(true);
LookupUtils.setFieldQuickfinder(alBusinessObject, KFSPropertyConstants.ACCOUNT_NUMBER, accountField, Collections.singletonList(KFSPropertyConstants.ACCOUNT_NUMBER));
docSearchRows.add(new Row(Collections.singletonList(accountField)));
}
boolean displayedLedgerPostingDoc = false;
if (LaborLedgerPostingDocumentForSearching.class.isAssignableFrom(docClass)) {
Field searchField = FieldUtils.getPropertyField(GeneralLedgerPendingEntry.class, KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, true);
searchField.setFieldDataType(CoreConstants.DATA_TYPE_STRING);
LookupUtils.setFieldQuickfinder(new GeneralLedgerPendingEntry(), KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, searchField, Collections.singletonList(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE));
docSearchRows.add(new Row(Collections.singletonList(searchField)));
displayedLedgerPostingDoc = true;
}
if (GeneralLedgerPostingDocument.class.isAssignableFrom(docClass) && !displayedLedgerPostingDoc) {
Field searchField = FieldUtils.getPropertyField(GeneralLedgerPendingEntry.class, KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, true);
searchField.setFieldDataType(CoreConstants.DATA_TYPE_STRING);
LookupUtils.setFieldQuickfinder(new GeneralLedgerPendingEntry(), KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, searchField, Collections.singletonList(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE));
docSearchRows.add(new Row(Collections.singletonList(searchField)));
}
if (AmountTotaling.class.isAssignableFrom(docClass)) {
Field searchField = FieldUtils.getPropertyField(FinancialSystemDocumentHeader.class, KFSPropertyConstants.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, true);
searchField.setFieldDataType(CoreConstants.DATA_TYPE_FLOAT);
docSearchRows.add(new Row(Collections.singletonList(searchField)));
}
}
Row resultType = createSearchResultDisplayTypeRow();
docSearchRows.add(resultType);
if (LOG.isDebugEnabled()) {
LOG.debug("Returning Rows: " + docSearchRows);
}
return docSearchRows;
}
use of org.kuali.kfs.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.kfs.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.kfs.krad.bo.BusinessObject in project cu-kfs by CU-CommunityApps.
the class KualiInquiryAction method downloadCustomBOAttachment.
public ActionForward downloadCustomBOAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String fileName = request.getParameter(KRADConstants.BO_ATTACHMENT_FILE_NAME);
String contentType = request.getParameter(KRADConstants.BO_ATTACHMENT_FILE_CONTENT_TYPE);
String fileContentBoField = request.getParameter(KRADConstants.BO_ATTACHMENT_FILE_CONTENT_FIELD);
// require certain request properties
if (fileName != null && contentType != null && fileContentBoField != null) {
// make sure user has authorization to download attachment
checkAuthorization(form, findMethodToCall(form, request));
fileName = StringUtils.replace(fileName, " ", "_");
InquiryForm inquiryForm = (InquiryForm) form;
BusinessObject bo = retrieveBOFromInquirable(inquiryForm);
checkBO(bo);
Class clazz = bo.getClass();
Method method = clazz.getMethod("get" + StringUtils.capitalize(fileContentBoField));
byte[] fileContents = (byte[]) method.invoke(bo);
streamToResponse(fileContents, fileName, contentType, response);
} else {
if (fileName == null) {
LOG.error("Request Parameter \"" + KRADConstants.BO_ATTACHMENT_FILE_NAME + "\" not provided.");
}
if (contentType == null) {
LOG.error("Request Parameter \"" + KRADConstants.BO_ATTACHMENT_FILE_CONTENT_TYPE + "\" not provided.");
}
if (fileContentBoField == null) {
LOG.error("Request Parameter \"" + KRADConstants.BO_ATTACHMENT_FILE_CONTENT_FIELD + "\" not provided.");
}
}
return null;
}
Aggregations