Search in sources :

Example 1 with DocumentRouteHeaderValue

use of org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue in project cu-kfs by CU-CommunityApps.

the class AdvanceDepositServiceImpl method retrieveAdvanceDepositDocumentsToRoute.

/**
 * Returns a list of all initiated but not yet routed advance deposit documents, using the WorkflowDocumentService.
 *
 * @return a list of advance deposit documents to route
 */
protected List<String> retrieveAdvanceDepositDocumentsToRoute(String statusCode) throws WorkflowException, RemoteException {
    List<String> documentIds = new ArrayList<String>();
    List<DocumentStatus> routeStatuses = new ArrayList<DocumentStatus>();
    routeStatuses.add(DocumentStatus.fromCode(statusCode));
    Person systemUser = getPersonService().getPersonByPrincipalName(KFSConstants.SYSTEM_USER);
    String principalName = systemUser.getPrincipalName();
    DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create();
    criteria.setDocumentTypeName(KFSConstants.FinancialDocumentTypeCodes.ADVANCE_DEPOSIT);
    criteria.setDocumentStatuses(routeStatuses);
    criteria.setInitiatorPrincipalName(principalName);
    DocumentSearchResults results = getDocumentSearchService().lookupDocuments(systemUser.getPrincipalId(), criteria.build());
    for (DocumentSearchResult resultRow : results.getSearchResults()) {
        DocumentRouteHeaderValue document = resultRow.getDocument();
        if (ObjectUtils.isNotNull(document)) {
            documentIds.add(document.getDocumentId());
        }
    }
    return documentIds;
}
Also used : DocumentStatus(org.kuali.kfs.kew.api.document.DocumentStatus) DocumentSearchResult(org.kuali.kfs.kew.api.document.search.DocumentSearchResult) DocumentSearchCriteria(org.kuali.kfs.kew.api.document.search.DocumentSearchCriteria) DocumentSearchResults(org.kuali.kfs.kew.api.document.search.DocumentSearchResults) ArrayList(java.util.ArrayList) Person(org.kuali.kfs.kim.api.identity.Person) DocumentRouteHeaderValue(org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue)

Example 2 with DocumentRouteHeaderValue

use of org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue in project cu-kfs by CU-CommunityApps.

the class CuAutoDisapproveDocumentsServiceImpl method getDocumentsWithActualWorkflowStatus.

/**
 * CU Customization:
 *
 * There is a known issue where the KFS document headers are not auto-saved when a KFS
 * document gets recalled to the action list. The auto-saves are not being performed to
 * explicitly avoid Optimistic Locking problems for end users in the PostProcessorServiceImpl
 * code on documents that are being moved into SAVED status.
 *
 * Therefore, to prevent problems with auto-disapprovals accidentally targeting recalled
 * documents (due to them being retrieved based on KFS document header status), this method
 * filters out any documents whose KEW doc statuses do not match the expected one.
 *
 * @param documentList The document headers to filter; cannot be null.
 * @param workflowStatus The workflow status that the documents are expected to have; cannot be null.
 * @return A new collection containing only the KFS doc headers whose matching route headers actually have the given workflow status.
 */
protected Collection<FinancialSystemDocumentHeader> getDocumentsWithActualWorkflowStatus(Collection<FinancialSystemDocumentHeader> documentList, DocumentStatus status) {
    final int SCALED_SET_SIZE = (int) (documentList.size() * 1.4);
    Set<String> documentIds = new HashSet<String>(SCALED_SET_SIZE);
    Collection<DocumentRouteHeaderValue> routeHeaders;
    Collection<FinancialSystemDocumentHeader> finalList = new ArrayList<FinancialSystemDocumentHeader>(documentList.size());
    // Assemble document IDs, then search for workflow headers.
    for (FinancialSystemDocumentHeader docHeader : documentList) {
        documentIds.add(docHeader.getDocumentNumber());
    }
    routeHeaders = routeHeaderService.getRouteHeaders(documentIds);
    // Track which headers have the expected document status.
    documentIds = new HashSet<String>(SCALED_SET_SIZE);
    if (routeHeaders != null) {
        for (DocumentRouteHeaderValue routeHeader : routeHeaders) {
            if (status.equals(routeHeader.getStatus())) {
                documentIds.add(routeHeader.getDocumentId());
            }
        }
    }
    // Update final-headers collection with any doc headers that actually have the given workflow status in KEW.
    for (FinancialSystemDocumentHeader docHeader : documentList) {
        if (documentIds.contains(docHeader.getDocumentNumber())) {
            finalList.add(docHeader);
        }
    }
    return finalList;
}
Also used : FinancialSystemDocumentHeader(org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader) ArrayList(java.util.ArrayList) DocumentRouteHeaderValue(org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue) HashSet(java.util.HashSet)

Example 3 with DocumentRouteHeaderValue

use of org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue in project cu-kfs by CU-CommunityApps.

the class TransactionRowBuilder method getWorkflowDocumentForTaxRow.

/**
 * Helper method for retrieving the workflow document of the current tax source row,
 * and for updating statistics accordingly if the document could not be found.
 *
 * <p>NOTE: In order for this method to work as intended, the list of doc IDs for
 * retrieval *MUST* be sorted in ascending order, and the invocations of this method
 * for a given builder *MUST* pass in the individual document IDs in ascending order
 * (preferably with null/blank values coming first).</p>
 *
 * @param documentId The document's ID; may be blank.
 * @param summary The object encapsulating the tax-type-specific summary info.
 * @return The workflow document for the current tax row, or null if no such document exists.
 */
@SuppressWarnings("unchecked")
DocumentRouteHeaderValue getWorkflowDocumentForTaxRow(String documentId, T summary) {
    if (StringUtils.isNotBlank(documentId)) {
        int idCompareResult = documentId.compareTo(currentDocument.getDocumentId());
        if (idCompareResult > 0) {
            // If no match and doc ID is greater than cached one, then get next document from bulk-retrieved ones.
            do {
                while (documentsForProcessing.hasNext() && idCompareResult > 0) {
                    currentDocument = documentsForProcessing.next();
                    idCompareResult = documentId.compareTo(currentDocument.getDocumentId());
                }
                // If still greater than cached ID and more unfetched docs exist, perform next bulk retrieval.
                if (idCompareResult > 0 && documentIdsForBulkQuery.hasNext()) {
                    StringBuilder docIdCriteria = new StringBuilder(DOC_ID_CRITERIA_SIZE);
                    for (int i = 0; documentIdsForBulkQuery.hasNext() && i < getMaxSearchSize(); i++) {
                        // Build a docId criteria string with "|" (Kuali lookup OR) as the separator.
                        docIdCriteria.append(documentIdsForBulkQuery.next()).append('|');
                    }
                    // Remove last unneeded "|" separator.
                    docIdCriteria.deleteCharAt(docIdCriteria.length() - 1);
                    // Get and sort the documents.
                    DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create();
                    criteria.setDocumentId(docIdCriteria.toString());
                    DocumentSearchResults results = documentSearchService.lookupDocuments(null, criteria.build());
                    documentsForBatch = new ArrayList<DocumentRouteHeaderValue>(results.getSearchResults().size());
                    for (DocumentSearchResult result : results.getSearchResults()) {
                        documentsForBatch.add(result.getDocument());
                    }
                    Collections.sort(documentsForBatch, new BeanPropertyComparator(Collections.singletonList(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_ID)));
                    documentsForProcessing = documentsForBatch.iterator();
                    // Select and compare first document from new batch, if non-empty.
                    if (documentsForProcessing.hasNext()) {
                        currentDocument = documentsForProcessing.next();
                        idCompareResult = documentId.compareTo(currentDocument.getDocumentId());
                    }
                }
            // Keep looping until doc ID is less than or equal to cached one, or until cached values are exhausted.
            } while (idCompareResult > 0 && (documentsForProcessing.hasNext() || documentIdsForBulkQuery.hasNext()));
        }
        if (idCompareResult == 0) {
            // Return document if found.
            return currentDocument;
        }
        // No document was found, so update statistics and return null.
        numNoDocumentHeaders++;
    } else {
        numNullDocumentHeaders++;
    }
    return null;
}
Also used : DocumentSearchResult(org.kuali.kfs.kew.api.document.search.DocumentSearchResult) DocumentSearchCriteria(org.kuali.kfs.kew.api.document.search.DocumentSearchCriteria) DocumentSearchResults(org.kuali.kfs.kew.api.document.search.DocumentSearchResults) BeanPropertyComparator(org.kuali.kfs.krad.util.BeanPropertyComparator) DocumentRouteHeaderValue(org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue)

Example 4 with DocumentRouteHeaderValue

use of org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue in project cu-kfs by CU-CommunityApps.

the class TransactionRowPRNCBuilder method updateTransactionRowsFromWorkflowDocuments.

@Override
void updateTransactionRowsFromWorkflowDocuments(ResultSet rs, T summary) throws SQLException {
    TransactionDetailRow detailRow = summary.transactionDetailRow;
    String documentId;
    String initiatorPrincipalId;
    String initiatorPrincipalName;
    String paymentMethodCode;
    String vendorTaxNumber;
    java.sql.Date dateFinalized;
    DocumentRouteHeaderValue document;
    DocumentStatus documentStatus = null;
    boolean processCurrentRow;
    boolean useDateFinalized;
    java.sql.Date startDate = summary.getStartDate();
    java.sql.Date endDate = summary.getEndDate();
    // Update or remove rows as needed.
    while (rs.next()) {
        String documentType = rs.getString(detailRow.documentType.index);
        // Retrieve payment method, which is temporarily stored in the doc title field.
        paymentMethodCode = rs.getString(detailRow.documentTitle.index);
        if (isPaymentRequestDocument(documentType) && isForeignOrWireTransferPaymentMethod(summary, paymentMethodCode)) {
            // Initialized minimal variables for current row.
            processCurrentRow = true;
            documentId = rs.getString(detailRow.documentNumber.index);
            initiatorPrincipalId = null;
            documentStatus = null;
            dateFinalized = null;
            useDateFinalized = false;
            // Retrieve document info.
            document = getWorkflowDocumentForTaxRow(documentId, summary);
            if (document != null) {
                initiatorPrincipalId = document.getInitiatorPrincipalId();
                documentStatus = document.getStatus();
                if (document.getDateFinalized() != null) {
                    dateFinalized = new java.sql.Date(document.getDateFinalized().getMillis());
                }
            }
            // Depending on payment method, verify that the PRNC has indeed been finalized during the given time period.
            if (summary.foreignDraftCode.equals(paymentMethodCode) || summary.wireTransferCode.equals(paymentMethodCode)) {
                // If a Foreign Draft or Wire Transfer, check the doc finalization date and status.
                if (DocumentStatus.FINAL.equals(documentStatus) && dateFinalized != null && dateFinalized.compareTo(startDate) >= 0 && dateFinalized.compareTo(endDate) <= 0) {
                    // If finalized during the current reporting period, then increment counters accordingly and use finalize date as payment date.
                    useDateFinalized = true;
                    if (summary.foreignDraftCode.equals(paymentMethodCode)) {
                        numForeignDraftsSelected++;
                    } else if (summary.wireTransferCode.equals(paymentMethodCode)) {
                        numWireTransfersSelected++;
                    }
                } else {
                    // If not finalized or if in the wrong reporting period, then skip the current PRNC data row.
                    if (summary.foreignDraftCode.equals(paymentMethodCode)) {
                        numForeignDraftsIgnored++;
                    } else if (summary.wireTransferCode.equals(paymentMethodCode)) {
                        numWireTransfersIgnored++;
                    }
                    // Skip any further processing for the current row.
                    processCurrentRow = false;
                }
            }
            if (processCurrentRow) {
                // Finish initialization.
                vendorTaxNumber = rs.getString(detailRow.vendorTaxNumber.index);
                // Check for null objects as needed, and get the initiator's principal name.
                initiatorPrincipalName = checkForEntityAndAccountAndOrgExistence(initiatorPrincipalId, rs.getString(detailRow.chartCode.index), rs.getString(detailRow.accountNumber.index), summary);
                // If vendor tax number is blank, then replace with a generated value accordingly.
                if (StringUtils.isBlank(vendorTaxNumber)) {
                    vendorTaxNumber = getReplacementVendorTaxNumber(rs.getString(detailRow.payeeId.index), summary);
                    rs.updateString(detailRow.vendorTaxNumber.index, vendorTaxNumber);
                }
                // Do tax-type-specific updates.
                doTaxSpecificSecondPassRowSetup(rs, summary);
                // Update other fields as needed.
                if (StringUtils.isBlank(documentId)) {
                    rs.updateString(detailRow.documentNumber.index, CUTaxConstants.DOC_ID_ZERO);
                }
                rs.updateString(detailRow.documentTitle.index, (document != null && StringUtils.isNotBlank(document.getTitle())) ? document.getTitle() : CUTaxConstants.DOC_TITLE_IF_NOT_FOUND);
                rs.updateString(detailRow.initiatorNetId.index, StringUtils.isNotBlank(initiatorPrincipalName) ? initiatorPrincipalName : CUTaxConstants.NETID_IF_NOT_FOUND);
                if (useDateFinalized) {
                    rs.updateDate(detailRow.paymentDate.index, dateFinalized);
                }
                // Update the transaction row.
                rs.updateRow();
            } else {
                // If a Foreign Draft or Wire Transfer that wasn't finalized or was in the wrong reporting period, then delete the row.
                rs.deleteRow();
            }
        }
    }
}
Also used : DocumentStatus(org.kuali.kfs.kew.api.document.DocumentStatus) TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow) DocumentRouteHeaderValue(org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue)

Example 5 with DocumentRouteHeaderValue

use of org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue in project cu-kfs by CU-CommunityApps.

the class TransactionRowDvBuilder method updateTransactionRowsFromWorkflowDocuments.

@Override
void updateTransactionRowsFromWorkflowDocuments(ResultSet rs, T summary) throws SQLException {
    TransactionDetailRow detailRow = summary.transactionDetailRow;
    Pattern nonPrintableCharsPattern = Pattern.compile("[^\\p{Graph}\\p{Space}]");
    String documentId;
    String initiatorPrincipalId;
    String initiatorPrincipalName;
    String paymentMethodCode;
    String vendorTaxNumber;
    String checkStubText;
    Matcher checkStubMatcher;
    java.sql.Date dateFinalized;
    DocumentRouteHeaderValue document;
    DocumentStatus documentStatus = null;
    boolean processCurrentRow;
    boolean useDateFinalized;
    java.sql.Date startDate = summary.getStartDate();
    java.sql.Date endDate = summary.getEndDate();
    // Update or remove rows as needed.
    while (rs.next()) {
        // Only update DV-related rows.
        if (DisbursementVoucherConstants.DOCUMENT_TYPE_CODE.equals(rs.getString(detailRow.documentType.index))) {
            // Initialized minimal variables for current row.
            processCurrentRow = true;
            documentId = rs.getString(detailRow.documentNumber.index);
            initiatorPrincipalId = null;
            documentStatus = null;
            dateFinalized = null;
            useDateFinalized = false;
            // Retrieve document info.
            document = getWorkflowDocumentForTaxRow(documentId, summary);
            if (document != null) {
                initiatorPrincipalId = document.getInitiatorPrincipalId();
                documentStatus = document.getStatus();
                if (document.getDateFinalized() != null) {
                    dateFinalized = new java.sql.Date(document.getDateFinalized().getMillis());
                }
            }
            // Retrieve payment method, which is temporarily stored in the doc title field.
            paymentMethodCode = rs.getString(detailRow.documentTitle.index);
            // Depending on payment method, verify that the DV has indeed been finalized during the given time period.
            if (summary.foreignDraftCode.equals(paymentMethodCode) || summary.wireTransferCode.equals(paymentMethodCode)) {
                // If a Foreign Draft or Wire Transfer, check the doc finalization date and status.
                if (DocumentStatus.FINAL.equals(documentStatus) && dateFinalized != null && dateFinalized.compareTo(startDate) >= 0 && dateFinalized.compareTo(endDate) <= 0) {
                    // If finalized during the current reporting period, then increment counters accordingly and use finalize date as payment date.
                    useDateFinalized = true;
                    if (summary.foreignDraftCode.equals(paymentMethodCode)) {
                        numForeignDraftsSelected++;
                    } else if (summary.wireTransferCode.equals(paymentMethodCode)) {
                        numWireTransfersSelected++;
                    }
                } else {
                    // If not finalized or if in the wrong reporting period, then skip the current DV data row.
                    if (summary.foreignDraftCode.equals(paymentMethodCode)) {
                        numForeignDraftsIgnored++;
                    } else if (summary.wireTransferCode.equals(paymentMethodCode)) {
                        numWireTransfersIgnored++;
                    }
                    // Skip any further processing for the current row.
                    processCurrentRow = false;
                }
            }
            if (processCurrentRow) {
                // Finish initialization.
                vendorTaxNumber = rs.getString(detailRow.vendorTaxNumber.index);
                checkStubText = rs.getString(detailRow.dvCheckStubText.index);
                checkStubMatcher = nonPrintableCharsPattern.matcher((checkStubText != null) ? checkStubText : KFSConstants.EMPTY_STRING);
                // Check for null objects as needed, and get the initiator's principal name.
                initiatorPrincipalName = checkForEntityAndAccountAndOrgExistence(initiatorPrincipalId, rs.getString(detailRow.chartCode.index), rs.getString(detailRow.accountNumber.index), summary);
                // If vendor tax number is blank, then replace with a generated value accordingly.
                if (StringUtils.isBlank(vendorTaxNumber)) {
                    vendorTaxNumber = getReplacementVendorTaxNumber(rs.getString(detailRow.payeeId.index), summary);
                    rs.updateString(detailRow.vendorTaxNumber.index, vendorTaxNumber);
                }
                // Remove unprintable characters from the check stub text if necessary.
                if (checkStubMatcher.find()) {
                    checkStubText = checkStubMatcher.replaceAll(KFSConstants.EMPTY_STRING);
                    rs.updateString(detailRow.dvCheckStubText.index, checkStubText);
                    numDvCheckStubTextsAltered++;
                } else {
                    numDvCheckStubTextsNotAltered++;
                }
                // Do tax-type-specific updates.
                doTaxSpecificSecondPassRowSetup(rs, summary);
                // Update other fields as needed.
                if (StringUtils.isBlank(documentId)) {
                    rs.updateString(detailRow.documentNumber.index, CUTaxConstants.DOC_ID_ZERO);
                }
                rs.updateString(detailRow.documentTitle.index, (document != null && StringUtils.isNotBlank(document.getTitle())) ? document.getTitle() : CUTaxConstants.DOC_TITLE_IF_NOT_FOUND);
                rs.updateString(detailRow.initiatorNetId.index, StringUtils.isNotBlank(initiatorPrincipalName) ? initiatorPrincipalName : CUTaxConstants.NETID_IF_NOT_FOUND);
                if (useDateFinalized) {
                    rs.updateDate(detailRow.paymentDate.index, dateFinalized);
                }
                // Update the transaction row.
                rs.updateRow();
            } else {
                // If a Foreign Draft or Wire Transfer that wasn't finalized or was in the wrong reporting period, then delete the row.
                rs.deleteRow();
            }
        }
    }
}
Also used : DocumentStatus(org.kuali.kfs.kew.api.document.DocumentStatus) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow) DocumentRouteHeaderValue(org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue)

Aggregations

DocumentRouteHeaderValue (org.kuali.kfs.kew.routeheader.DocumentRouteHeaderValue)16 ParseException (java.text.ParseException)5 ActionMessage (org.apache.struts.action.ActionMessage)5 ActionMessages (org.apache.struts.action.ActionMessages)5 WorkflowRuntimeException (org.kuali.kfs.kew.api.WorkflowRuntimeException)5 WorkflowServiceErrorException (org.kuali.kfs.kew.exception.WorkflowServiceErrorException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ServletException (javax.servlet.ServletException)4 TransactionDetailRow (edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow)3 HashSet (java.util.HashSet)3 DocumentStatus (org.kuali.kfs.kew.api.document.DocumentStatus)3 Iterator (java.util.Iterator)2 List (java.util.List)2 DocumentOrchestrationConfig (org.kuali.kfs.kew.api.document.DocumentOrchestrationConfig)2 DocumentOrchestrationQueue (org.kuali.kfs.kew.api.document.DocumentOrchestrationQueue)2 DocumentProcessingOptions (org.kuali.kfs.kew.api.document.DocumentProcessingOptions)2 DocumentSearchCriteria (org.kuali.kfs.kew.api.document.search.DocumentSearchCriteria)2 DocumentSearchResult (org.kuali.kfs.kew.api.document.search.DocumentSearchResult)2 DocumentSearchResults (org.kuali.kfs.kew.api.document.search.DocumentSearchResults)2