Search in sources :

Example 1 with CreateAccountingDocumentReportItemDetail

use of edu.cornell.kfs.fp.batch.CreateAccountingDocumentReportItemDetail in project cu-kfs by CU-CommunityApps.

the class CreateAccountingDocumentServiceImpl method processAccountingDocumentEntryFromXml.

protected void processAccountingDocumentEntryFromXml(AccountingXmlDocumentEntry accountingXmlDocument, CreateAccountingDocumentReportItem reportItem) {
    GlobalVariables.getMessageMap().clearErrorMessages();
    CreateAccountingDocumentReportItemDetail detail = new CreateAccountingDocumentReportItemDetail();
    detail.setIndexNumber(accountingXmlDocument.getIndex().intValue());
    detail.setDocumentType(accountingXmlDocument.getDocumentTypeCode());
    detail.setDocumentDescription(accountingXmlDocument.getDescription());
    detail.setDocumentExplanation(accountingXmlDocument.getExplanation());
    try {
        LOG.info("processAccountingDocumentEntryFromXml: 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("processAccountingDocumentEntryFromXml: Finished processing and routing accounting document " + document.getDocumentNumber() + " of type: " + accountingXmlDocument.getDocumentTypeCode());
        detail.setSuccessfullyRouted(true);
        detail.setDocumentNumber(document.getDocumentNumber());
        reportItem.getDocumentsSuccessfullyRouted().add(detail);
    } catch (Exception e) {
        detail.setSuccessfullyRouted(false);
        if (e instanceof ValidationException) {
            String errorMessage = buildValidationErrorMessage((ValidationException) e);
            LOG.error("processAccountingDocumentEntryFromXml: Could not route accounting document - " + errorMessage);
            detail.setErrorMessage(errorMessage);
        } else {
            LOG.error("processAccountingDocumentEntryFromXml: Error processing accounting XML document", e);
            detail.setErrorMessage("Non validation error: " + e.getMessage());
        }
        reportItem.getDocumentsInError().add(detail);
    } finally {
        GlobalVariables.getMessageMap().clearErrorMessages();
    }
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) ValidationException(org.kuali.kfs.krad.exception.ValidationException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) IOException(java.io.IOException) CreateAccountingDocumentReportItemDetail(edu.cornell.kfs.fp.batch.CreateAccountingDocumentReportItemDetail)

Aggregations

CreateAccountingDocumentReportItemDetail (edu.cornell.kfs.fp.batch.CreateAccountingDocumentReportItemDetail)1 IOException (java.io.IOException)1 ValidationException (org.kuali.kfs.krad.exception.ValidationException)1 AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)1 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)1