use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CreateAccountingDocumentServiceImpl method createAndRouteAccountingDocumentFromXml.
protected void createAndRouteAccountingDocumentFromXml(AccountingXmlDocumentEntry accountingXmlDocument, CreateAccountingDocumentReportItemDetail reportDetail, CreateAccountingDocumentReportItem reportItem) {
try {
LOG.info("createAndRouteAccountingDocumentFromXml: Started processing accounting document of type: " + accountingXmlDocument.getDocumentTypeCode());
String documentGeneratorBeanName = CuFPConstants.ACCOUNTING_DOCUMENT_GENERATOR_BEAN_PREFIX + accountingXmlDocument.getDocumentTypeCode();
AccountingDocumentGenerator<? extends AccountingDocument> documentGenerator = findDocumentGenerator(documentGeneratorBeanName);
AccountingDocument document = documentGenerator.createDocument(this::getNewDocument, accountingXmlDocument);
document = (AccountingDocument) documentService.routeDocument(document, CuFPConstants.ACCOUNTING_DOCUMENT_XML_ROUTE_ANNOTATION, getAllAdHocRecipients(document));
LOG.info("createAndRouteAccountingDocumentFromXml: Finished processing and routing accounting document " + document.getDocumentNumber() + " of type: " + accountingXmlDocument.getDocumentTypeCode());
reportDetail.setSuccessfullyRouted(true);
reportDetail.setDocumentNumber(document.getDocumentNumber());
reportItem.getDocumentsSuccessfullyRouted().add(reportDetail);
} catch (RuntimeException | WorkflowException e) {
reportDetail.setSuccessfullyRouted(false);
if (e instanceof ValidationException) {
String errorMessage = buildValidationErrorMessage((ValidationException) e);
LOG.error("createAndRouteAccountingDocumentFromXml: Could not route accounting document - " + errorMessage);
reportDetail.setErrorMessage(errorMessage);
} else {
LOG.error("createAndRouteAccountingDocumentFromXml: Error processing accounting XML document", e);
reportDetail.setErrorMessage("Non validation error: " + e.getMessage());
reportItem.setNonBusinessRuleFailure(true);
}
reportItem.getDocumentsInError().add(reportDetail);
} finally {
GlobalVariables.getMessageMap().clearErrorMessages();
}
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class ProcurementCardCreateDocumentServiceImpl method createProcurementCardDocument.
/**
* Creates a ProcurementCardDocument from the List of transactions given.
*
* @param transactions List of ProcurementCardTransaction objects to be used for creating the document.
* @return A ProcurementCardDocument populated with the transactions provided.
*/
@SuppressWarnings({ "rawtypes", "deprecation" })
@Override
public ProcurementCardDocument createProcurementCardDocument(List transactions) {
ProcurementCardDocument pcardDocument = null;
try {
// get new document from doc service
pcardDocument = buildNewProcurementCardDocument();
List<CapitalAssetInformation> capitalAssets = pcardDocument.getCapitalAssetInformation();
for (CapitalAssetInformation capitalAsset : capitalAssets) {
if (ObjectUtils.isNotNull(capitalAsset) && ObjectUtils.isNotNull(capitalAsset.getCapitalAssetInformationDetails())) {
capitalAsset.setDocumentNumber(pcardDocument.getDocumentNumber());
}
}
ProcurementCardTransaction trans = (ProcurementCardTransaction) transactions.get(0);
String errorText = validateTransaction(trans);
createCardHolderRecord(pcardDocument, trans);
// for each transaction, create transaction detail object and then acct lines for the detail
int transactionLineNumber = 1;
KualiDecimal documentTotalAmount = KualiDecimal.ZERO;
ProcurementCardTransaction transaction = null;
for (Object transactionObj : transactions) {
transaction = (ProcurementCardTransaction) transactionObj;
// create transaction detail record with accounting lines
errorText += createTransactionDetailRecord(pcardDocument, transaction, transactionLineNumber);
// update document total
documentTotalAmount = documentTotalAmount.add(transaction.getFinancialDocumentTotalAmount());
transactionLineNumber++;
}
pcardDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(documentTotalAmount);
// pcardDocument.getDocumentHeader().setDocumentDescription("SYSTEM Generated");
transaction = (ProcurementCardTransaction) transactions.get(0);
String cardHolderName = transaction.getCardHolderName();
String vendorName = transaction.getVendorName();
String transactionType = ((ProcurementCardTransactionExtendedAttribute) transaction.getExtension()).getTransactionType();
if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
VENDOR_NAME_MAX_LENGTH = 16;
} else {
VENDOR_NAME_MAX_LENGTH = 19;
}
if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() > VENDOR_NAME_MAX_LENGTH) {
cardHolderName = cardHolderName.substring(0, CARD_HOLDER_MAX_LENGTH);
vendorName = vendorName.substring(0, VENDOR_NAME_MAX_LENGTH);
}
if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() <= VENDOR_NAME_MAX_LENGTH) {
Integer endIndice = 0;
if ((CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length())) > cardHolderName.length()) {
endIndice = cardHolderName.length();
} else {
endIndice = CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length());
}
cardHolderName = cardHolderName.substring(0, endIndice);
}
if (vendorName.length() > VENDOR_NAME_MAX_LENGTH && cardHolderName.length() <= CARD_HOLDER_MAX_LENGTH) {
Integer endIndice = 0;
if ((VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length())) > vendorName.length()) {
endIndice = vendorName.length();
} else {
endIndice = VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length());
}
vendorName = vendorName.substring(0, endIndice);
}
String creditCardNumber = transaction.getTransactionCreditCardNumber();
String lastFour = "";
if (creditCardNumber.length() > CC_LAST_FOUR) {
lastFour = creditCardNumber.substring(creditCardNumber.length() - CC_LAST_FOUR);
}
String docDesc = cardHolderName + "/" + vendorName + "/" + lastFour;
if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
docDesc = transactionType + "/" + cardHolderName + "/" + vendorName + "/" + lastFour;
}
if (docDesc.length() > MAX_DOC_DESC_LENGTH) {
docDesc = docDesc.substring(0, MAX_DOC_DESC_LENGTH);
}
pcardDocument.getDocumentHeader().setDocumentDescription(docDesc);
// Remove duplicate messages from errorText
String[] messages = StringUtils.split(errorText, ".");
for (String message : messages) {
int countMatches = StringUtils.countMatches(errorText, message) - 1;
errorText = StringUtils.replace(errorText, message + ".", "", countMatches);
}
// In case errorText is still too long, truncate it and indicate so.
Integer documentExplanationMaxLength = dataDictionaryService.getAttributeMaxLength(DocumentHeader.class.getName(), KFSPropertyConstants.EXPLANATION);
if (documentExplanationMaxLength != null && errorText.length() > documentExplanationMaxLength.intValue()) {
String truncatedMessage = " ... TRUNCATED.";
errorText = errorText.substring(0, documentExplanationMaxLength - truncatedMessage.length()) + truncatedMessage;
}
pcardDocument.getDocumentHeader().setExplanation(errorText);
} catch (WorkflowException e) {
LOG.error("Error creating pcdo documents: " + e.getMessage(), e);
throw new RuntimeException("Error creating pcdo documents: " + e.getMessage(), e);
}
return pcardDocument;
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class SubmitTripWebServiceImpl method buildDistributionIncomeExpenseDocument.
/**
* @param diDescription
* @param diExplanation
* @param tripNumber
* @param initiatorNetId
* @return
* @throws Exception
*/
private String buildDistributionIncomeExpenseDocument(String diDescription, String diExplanation, String tripNumber, String initiatorNetId) throws Exception {
try {
if (!isValidDocumentInitiator(initiatorNetId, DISTRIBUTION_INCOME_EXPENSE)) {
throw new RuntimeException("Initiator identified does not have permission to create a DI.");
}
} catch (Exception ex) {
throw new RuntimeException("Initiator identified does not have permission to create a DI.", ex);
}
// create and route doc as system user
GlobalVariables.setUserSession(new UserSession(initiatorNetId));
MessageMap documentErrorMap = new MessageMap();
GlobalVariables.setMessageMap(documentErrorMap);
// Create document with description provided
CuDistributionOfIncomeAndExpenseDocument diDoc = null;
try {
diDoc = (CuDistributionOfIncomeAndExpenseDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DistributionOfIncomeAndExpenseDocument.class);
} catch (WorkflowException e) {
throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
}
if (diDoc != null) {
diDoc.getDocumentHeader().setDocumentDescription(diDescription);
diDoc.getDocumentHeader().setExplanation(diExplanation);
diDoc.getDocumentHeader().setOrganizationDocumentNumber(tripNumber);
diDoc.setTripAssociationStatusCode(CULegacyTravelServiceImpl.TRIP_ASSOCIATIONS.IS_TRIP_DOC);
diDoc.setTripId(tripNumber);
// Persist document
SpringContext.getBean(DocumentService.class).saveDocument(diDoc);
return diDoc.getDocumentNumber();
} else {
return "";
}
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class RecurringDisbursementVoucherDocumentServiceImpl method noteChangeOnRecurringDV.
private void noteChangeOnRecurringDV(RecurringDisbursementVoucherDocument recurringDV, String noteText, Set<String> setOfStrings) {
if (!setOfStrings.isEmpty()) {
Note note = buildNoteBase();
note.setNoteText(noteText + StringUtils.join(setOfStrings, ", "));
;
recurringDV.addNote(note);
try {
getDocumentService().saveDocument(recurringDV);
} catch (WorkflowException e) {
throw new RuntimeException("noteChangeOnRecurringDV() Unable to save note.", e);
}
}
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class RecurringDisbursementVoucherDocumentServiceImpl method cancelDisbursementVouchersFinalizedNotExtracted.
@Override
public Set<String> cancelDisbursementVouchersFinalizedNotExtracted(RecurringDisbursementVoucherDocument recurringDisbursementVoucherDocument, String cancelMessage) {
Set<String> canceledDVs = new HashSet<String>();
for (RecurringDisbursementVoucherDetail detail : recurringDisbursementVoucherDocument.getRecurringDisbursementVoucherDetails()) {
String dvDocumentNumber = detail.getDvDocumentNumber();
if (!isDVCancelable(dvDocumentNumber)) {
CuDisbursementVoucherDocument dv;
try {
dv = (CuDisbursementVoucherDocument) getDocumentService().getByDocumentHeaderId(detail.getDvDocumentNumber());
if (isDvCancelableFromApprovedNotExtracted(dv)) {
Date cancelDate = new Date(Calendar.getInstance().getTimeInMillis());
dv.setCancelDate(cancelDate);
CuDisbursementVoucherDocument cancledDV = (CuDisbursementVoucherDocument) getDocumentService().saveDocument(dv);
getCuDisbursementVoucherExtractionHelperService().getPaymentSourceHelperService().handleEntryCancellation(cancledDV, getCuDisbursementVoucherExtractionHelperService());
canceledDVs.add(cancledDV.getDocumentNumber());
}
} catch (WorkflowException e) {
throw new RuntimeException(e);
}
}
}
noteChangeOnRecurringDV(recurringDisbursementVoucherDocument, "The following disbursement vouchers were canceled after it was approved but before payments were created: ", canceledDVs);
return canceledDVs;
}
Aggregations