use of org.kuali.kfs.module.purap.exception.ItemParserException in project cu-kfs by CU-CommunityApps.
the class PurchasingActionBase method importItems.
/**
* Import items to the document from a spreadsheet.
*
* @param mapping An ActionMapping
* @param form An ActionForm
* @param request The HttpServletRequest
* @param response The HttpServletResponse
* @return An ActionForward
* @throws Exception
*/
public ActionForward importItems(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
LOG.info("Importing item lines");
PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
PurchasingDocument purDocument = (PurchasingDocument) purchasingForm.getDocument();
String documentNumber = purDocument.getDocumentNumber();
FormFile itemFile = purchasingForm.getItemImportFile();
Class itemClass = purDocument.getItemClass();
List<PurApItem> importedItems = null;
String errorPath = PurapConstants.ITEM_TAB_ERRORS;
ItemParser itemParser = purDocument.getItemParser();
// starting position of the imported items, equals the # of
int itemLinePosition = purDocument.getItemLinePosition();
try {
importedItems = itemParser.importItems(itemFile, itemClass, documentNumber);
// validate imported items
boolean allPassed = true;
int itemLineNumber = 0;
for (PurApItem item : importedItems) {
// Before the validation, set the item line number to the same as the line number in the import file (starting from
// 1)
// so that the error message will use the correct line number if there're errors for the current item line.
item.setItemLineNumber(++itemLineNumber);
allPassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedImportPurchasingAccountsPayableItemEvent("", purDocument, item));
// After the validation, set the item line number to the correct value as if it's added to the item list.
item.setItemLineNumber(itemLineNumber + itemLinePosition);
}
if (allPassed) {
updateBOReferenceforNewItems(importedItems, (PurchasingDocumentBase) purDocument);
purDocument.getItems().addAll(itemLinePosition, importedItems);
}
} catch (ItemParserException e) {
GlobalVariables.getMessageMap().putError(errorPath, e.getErrorKey(), e.getErrorParameters());
}
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Aggregations