Search in sources :

Example 1 with DocumentService

use of org.kuali.kfs.krad.service.DocumentService in project cu-kfs by CU-CommunityApps.

the class CUFinancialSystemDocumentServiceImpl method writeNote.

protected void writeNote(AccountingDocument accountingDocument, String noteText) {
    DocumentService documentService = SpringContext.getBean(DocumentService.class);
    // Put a note on the document to record the change to the address
    try {
        // String noteText = buildLineChangedNoteText(newAccountingLine, oldAccountingLine);
        int noteMaxSize = SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength("Note", "noteText");
        // Break up the note into multiple pieces if the note is too large to fit in the database field.
        while (noteText.length() > noteMaxSize) {
            int fromIndex = 0;
            fromIndex = noteText.lastIndexOf(';', noteMaxSize);
            String noteText1 = noteText.substring(0, fromIndex);
            Note note1 = documentService.createNoteFromDocument(accountingDocument, noteText1);
            accountingDocument.addNote(note1);
            noteText = noteText.substring(fromIndex);
        }
        Note note = documentService.createNoteFromDocument(accountingDocument, noteText);
        accountingDocument.addNote(note);
    } catch (Exception e) {
        LOG.error("Exception while attempting to create or add note: " + e);
    }
}
Also used : Note(org.kuali.kfs.krad.bo.Note) DocumentService(org.kuali.kfs.krad.service.DocumentService) CUFinancialSystemDocumentService(edu.cornell.kfs.sys.document.service.CUFinancialSystemDocumentService) DataDictionaryService(org.kuali.kfs.kns.service.DataDictionaryService) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException)

Example 2 with DocumentService

use of org.kuali.kfs.krad.service.DocumentService in project cu-kfs by CU-CommunityApps.

the class CUFinancialSystemDocumentServiceImpl method checkAccountingLinesForChanges.

/**
 *  new == null, old == null : no change; line deleted previously.
 *  new == blah, old == blah : no change
 *  new == blah, old == meh : changed
 *  new == null, old == blah : deleted
 *  new == blah, old == null : added
 * @throws WorkflowException
 *
 * @see org.kuali.kfs.sys.document.service.FinancialSystemDocumentService#checkAccountingLinesForChanges(org.kuali.kfs.sys.document.AccountingDocument)
 */
public void checkAccountingLinesForChanges(AccountingDocument accountingDocument) {
    DocumentService docService = SpringContext.getBean(DocumentService.class);
    AccountingDocument savedDoc = null;
    try {
        savedDoc = (AccountingDocument) docService.getByDocumentHeaderId(accountingDocument.getDocumentNumber());
    } catch (WorkflowException we) {
        LOG.error("Unable to retrieve document number " + accountingDocument.getDocumentNumber() + " to evaluate accounting line changes");
    }
    if (savedDoc == null) {
        return;
    }
    if (!accountingDocument.getSourceAccountingLines().isEmpty()) {
        Map<Integer, AccountingLine> newSourceLines = buildAccountingLineMap(accountingDocument.getSourceAccountingLines());
        Map<Integer, AccountingLine> savedSourceLines = buildAccountingLineMap(savedDoc.getSourceAccountingLines());
        if (newSourceLines.isEmpty())
            return;
        int maxSourceKey = findMinOrMaxKeyValue(newSourceLines, savedSourceLines, false);
        int minSourceKey = findMinOrMaxKeyValue(newSourceLines, savedSourceLines, true);
        for (int i = minSourceKey; i < maxSourceKey + 1; i++) {
            AccountingLine newLine = newSourceLines.get(i);
            AccountingLine oldLine = savedSourceLines.get(i);
            if (!compareTo(newLine, oldLine)) {
                String diff = buildLineChangedNoteText(newLine, oldLine);
                if (StringUtils.isNotBlank(diff)) {
                    writeNote(accountingDocument, diff);
                }
            }
        }
    }
    if (!accountingDocument.getTargetAccountingLines().isEmpty()) {
        Map<Integer, AccountingLine> newTargetLines = buildAccountingLineMap(accountingDocument.getTargetAccountingLines());
        Map<Integer, AccountingLine> savedTargetLines = buildAccountingLineMap(savedDoc.getTargetAccountingLines());
        if (newTargetLines.isEmpty())
            return;
        int maxTargetKey = findMinOrMaxKeyValue(newTargetLines, savedTargetLines, false);
        int minTargetKey = findMinOrMaxKeyValue(newTargetLines, savedTargetLines, true);
        for (int i = minTargetKey; i < maxTargetKey + 1; i++) {
            AccountingLine newLine = newTargetLines.get(i);
            AccountingLine oldLine = savedTargetLines.get(i);
            if (!compareTo(newLine, oldLine)) {
                String diff = buildLineChangedNoteText(newLine, oldLine);
                if (StringUtils.isNotBlank(diff)) {
                    writeNote(accountingDocument, diff);
                }
            }
        }
    }
}
Also used : AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) CUFinancialSystemDocumentService(edu.cornell.kfs.sys.document.service.CUFinancialSystemDocumentService)

Example 3 with DocumentService

use of org.kuali.kfs.krad.service.DocumentService in project cu-kfs by CU-CommunityApps.

the class FinancialSystemSearchableAttribute method extractDocumentAttributes.

@Override
public List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition, DocumentWithContent documentWithContent) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("extractDocumentAttributes( " + extensionDefinition + ", " + documentWithContent + " )");
    }
    List<DocumentAttribute> searchAttrValues = super.extractDocumentAttributes(extensionDefinition, documentWithContent);
    String docId = documentWithContent.getDocument().getDocumentId();
    DocumentService docService = SpringContext.getBean(DocumentService.class);
    Document doc = null;
    try {
        doc = docService.getByDocumentHeaderIdSessionless(docId);
    } catch (WorkflowException we) {
    }
    if (doc != null) {
        if (doc instanceof AmountTotaling && ((AmountTotaling) doc).getTotalDollarAmount() != null) {
            DocumentAttributeDecimal.Builder searchableAttributeValue = DocumentAttributeDecimal.Builder.create(KFSPropertyConstants.FINANCIAL_DOCUMENT_TOTAL_AMOUNT);
            searchableAttributeValue.setValue(((AmountTotaling) doc).getTotalDollarAmount().bigDecimalValue());
            searchAttrValues.add(searchableAttributeValue.build());
        }
        if (doc instanceof AccountingDocument) {
            AccountingDocument accountingDoc = (AccountingDocument) doc;
            searchAttrValues.addAll(harvestAccountingDocumentSearchableAttributes(accountingDoc));
        }
        boolean indexedLedgerDoc = false;
        if (doc instanceof LaborLedgerPostingDocumentForSearching) {
            LaborLedgerPostingDocumentForSearching LLPostingDoc = (LaborLedgerPostingDocumentForSearching) doc;
            searchAttrValues.addAll(harvestLLPDocumentSearchableAttributes(LLPostingDoc));
            indexedLedgerDoc = true;
        }
        if (doc instanceof GeneralLedgerPostingDocument && !indexedLedgerDoc) {
            GeneralLedgerPostingDocument GLPostingDoc = (GeneralLedgerPostingDocument) doc;
            searchAttrValues.addAll(harvestGLPDocumentSearchableAttributes(GLPostingDoc));
        }
        DocumentHeader docHeader = doc.getDocumentHeader();
        if (ObjectUtils.isNotNull(docHeader) && ObjectUtils.isNotNull(docHeader.getWorkflowDocument()) && CUKFSConstants.GACC_DOCUMENT_TYPE.equalsIgnoreCase(docHeader.getWorkflowDocument().getDocumentTypeName())) {
            for (AccountGlobalDetail detail : ((AccountGlobal) ((AccountGlobalMaintainableImpl) ((FinancialSystemMaintenanceDocument) doc).getNewMaintainableObject()).getBusinessObject()).getAccountGlobalDetails()) {
                if (!StringUtils.isBlank(detail.getAccountNumber())) {
                    DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(KFSPropertyConstants.ACCOUNT_NUMBER);
                    searchableAttributeValue.setValue(detail.getAccountNumber());
                    searchAttrValues.add(searchableAttributeValue.build());
                }
            }
        }
    }
    return searchAttrValues;
}
Also used : WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) DocumentAttributeDecimal(org.kuali.rice.kew.api.document.attribute.DocumentAttributeDecimal) DocumentAttributeString(org.kuali.rice.kew.api.document.attribute.DocumentAttributeString) Document(org.kuali.kfs.krad.document.Document) GeneralLedgerPostingDocument(org.kuali.kfs.sys.document.GeneralLedgerPostingDocument) FinancialSystemMaintenanceDocument(org.kuali.kfs.sys.document.FinancialSystemMaintenanceDocument) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) DocumentHeader(org.kuali.kfs.krad.bo.DocumentHeader) FinancialSystemDocumentHeader(org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader) DocumentService(org.kuali.kfs.krad.service.DocumentService) LaborLedgerPostingDocumentForSearching(org.kuali.kfs.integration.ld.LaborLedgerPostingDocumentForSearching) FinancialSystemMaintenanceDocument(org.kuali.kfs.sys.document.FinancialSystemMaintenanceDocument) GeneralLedgerPostingDocument(org.kuali.kfs.sys.document.GeneralLedgerPostingDocument) AccountGlobal(org.kuali.kfs.coa.businessobject.AccountGlobal) DocumentAttribute(org.kuali.rice.kew.api.document.attribute.DocumentAttribute) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail) DocumentAttributeString(org.kuali.rice.kew.api.document.attribute.DocumentAttributeString) AmountTotaling(org.kuali.kfs.sys.document.AmountTotaling)

Example 4 with DocumentService

use of org.kuali.kfs.krad.service.DocumentService in project cu-kfs by CU-CommunityApps.

the class CheckReconciliationMaintainableImpl method doRouteStatusChange.

/**
 * @see org.kuali.kfs.kns.maintenance.KualiMaintainableImpl#doRouteStatusChange(org.kuali.kfs.kns.bo.DocumentHeader)
 */
public void doRouteStatusChange(DocumentHeader documentHeader) {
    WorkflowDocument workflowDocument = documentHeader.getWorkflowDocument();
    if (workflowDocument.isProcessed() && !KFSConstants.MAINTENANCE_NEW_ACTION.equalsIgnoreCase(getMaintenanceAction())) {
        DocumentService documentService = SpringContext.getBean(DocumentService.class);
        MaintenanceDocument document;
        try {
            document = (MaintenanceDocument) documentService.getByDocumentHeaderId(documentHeader.getDocumentNumber());
            CheckReconciliation oldCr = (CheckReconciliation) document.getOldMaintainableObject().getBusinessObject();
            CheckReconciliation newCr = (CheckReconciliation) document.getNewMaintainableObject().getBusinessObject();
            if (ObjectUtils.isNotNull(oldCr) && !oldCr.getStatus().equalsIgnoreCase(newCr.getStatus())) {
                Date currentDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
                newCr.setStatusChangeDate(currentDate);
                // KFSUPGRADE-377
                if (CRConstants.CANCELLED.equalsIgnoreCase(newCr.getStatus())) {
                    newCr.setCancelDocHdrId(documentHeader.getDocumentNumber());
                }
            }
        } catch (WorkflowException e) {
            throw new RuntimeCacheException(e);
        }
    }
}
Also used : RuntimeCacheException(org.apache.ojb.broker.cache.RuntimeCacheException) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) CheckReconciliation(com.rsmart.kuali.kfs.cr.businessobject.CheckReconciliation) DateTimeService(org.kuali.rice.core.api.datetime.DateTimeService) DocumentService(org.kuali.kfs.krad.service.DocumentService) Date(java.sql.Date)

Example 5 with DocumentService

use of org.kuali.kfs.krad.service.DocumentService in project cu-kfs by CU-CommunityApps.

the class CuElectronicInvoiceHelperServiceImpl method routeEIRTDocuments.

protected boolean routeEIRTDocuments() {
    Collection<String> documentIdList = null;
    try {
        documentIdList = retrieveDocumentsToRoute(KewApiConstants.ROUTE_HEADER_SAVED_CD, ElectronicInvoiceRejectDocument.class);
    } catch (WorkflowException e1) {
        LOG.error("Error retrieving eirt documents for routing: " + e1.getMessage(), e1);
        throw new RuntimeException(e1.getMessage(), e1);
    } catch (RemoteException re) {
        LOG.error("Error retrieving eirt documents for routing: " + re.getMessage(), re);
        throw new RuntimeException(re.getMessage(), re);
    }
    // Collections.reverse(documentIdList);
    LOG.info("EIRTs to Route: " + documentIdList);
    DocumentService documentService = SpringContext.getBean(DocumentService.class);
    WorkflowDocumentService workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
    for (String eirtDocumentId : documentIdList) {
        try {
            LOG.info("Retrieving EIRT document # " + eirtDocumentId + ".");
            ElectronicInvoiceRejectDocument eirtDocument = (ElectronicInvoiceRejectDocument) documentService.getByDocumentHeaderId(eirtDocumentId);
            LOG.info("Routing EIRT document # " + eirtDocumentId + ".");
            documentService.prepareWorkflowDocument(eirtDocument);
            LOG.info("EIRT document # " + eirtDocumentId + " prepared for workflow.");
            // calling workflow service to bypass business rule checks
            workflowDocumentService.route(eirtDocument.getDocumentHeader().getWorkflowDocument(), "Routed by electronic invoice batch job", null);
            LOG.info("EIRT document # " + eirtDocumentId + " routed.");
        } catch (WorkflowException e) {
            LOG.error("Error routing document # " + eirtDocumentId + " " + e.getMessage());
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    return true;
}
Also used : ElectronicInvoiceRejectDocument(org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument) CuElectronicInvoiceRejectDocument(edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) RemoteException(java.rmi.RemoteException) WorkflowDocumentService(org.kuali.kfs.krad.workflow.service.WorkflowDocumentService) DocumentService(org.kuali.kfs.krad.service.DocumentService) FinancialSystemDocumentService(org.kuali.kfs.sys.document.service.FinancialSystemDocumentService)

Aggregations

DocumentService (org.kuali.kfs.krad.service.DocumentService)9 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)7 Document (org.kuali.kfs.krad.document.Document)3 AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)3 CUFinancialSystemDocumentService (edu.cornell.kfs.sys.document.service.CUFinancialSystemDocumentService)2 RemoteException (java.rmi.RemoteException)2 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)2 WorkflowDocumentService (org.kuali.kfs.krad.workflow.service.WorkflowDocumentService)2 FinancialSystemDocumentService (org.kuali.kfs.sys.document.service.FinancialSystemDocumentService)2 CheckReconciliation (com.rsmart.kuali.kfs.cr.businessobject.CheckReconciliation)1 CuElectronicInvoiceRejectDocument (edu.cornell.kfs.module.purap.document.CuElectronicInvoiceRejectDocument)1 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)1 Date (java.sql.Date)1 RuntimeCacheException (org.apache.ojb.broker.cache.RuntimeCacheException)1 AccountGlobal (org.kuali.kfs.coa.businessobject.AccountGlobal)1 AccountGlobalDetail (org.kuali.kfs.coa.businessobject.AccountGlobalDetail)1 InternalBillingDocument (org.kuali.kfs.fp.document.InternalBillingDocument)1 LaborLedgerPostingDocumentForSearching (org.kuali.kfs.integration.ld.LaborLedgerPostingDocumentForSearching)1 DataDictionaryService (org.kuali.kfs.kns.service.DataDictionaryService)1 DocumentHeader (org.kuali.kfs.krad.bo.DocumentHeader)1