Search in sources :

Example 1 with Document

use of org.kuali.rice.kew.api.document.Document 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 = getWorkflowDocumentService().documentSearch(systemUser.getPrincipalId(), criteria.build());
    for (DocumentSearchResult resultRow : results.getSearchResults()) {
        Document document = resultRow.getDocument();
        if (ObjectUtils.isNotNull(document)) {
            documentIds.add(document.getDocumentId());
        }
    }
    return documentIds;
}
Also used : DocumentStatus(org.kuali.rice.kew.api.document.DocumentStatus) DocumentSearchResult(org.kuali.rice.kew.api.document.search.DocumentSearchResult) DocumentSearchCriteria(org.kuali.rice.kew.api.document.search.DocumentSearchCriteria) DocumentSearchResults(org.kuali.rice.kew.api.document.search.DocumentSearchResults) ArrayList(java.util.ArrayList) Document(org.kuali.rice.kew.api.document.Document) AdvanceDepositDocument(org.kuali.kfs.fp.document.AdvanceDepositDocument) Person(org.kuali.rice.kim.api.identity.Person)

Example 2 with Document

use of org.kuali.rice.kew.api.document.Document 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")
Document 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 = workflowDocumentService.documentSearch(null, criteria.build());
                    documentsForBatch = new ArrayList<Document>(results.getSearchResults().size());
                    for (DocumentSearchResult result : results.getSearchResults()) {
                        documentsForBatch.add(result.getDocument());
                    }
                    Collections.sort(documentsForBatch, new BeanPropertyComparator(Collections.singletonList(KEWPropertyConstants.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.rice.kew.api.document.search.DocumentSearchResult) DocumentSearchCriteria(org.kuali.rice.kew.api.document.search.DocumentSearchCriteria) DocumentSearchResults(org.kuali.rice.kew.api.document.search.DocumentSearchResults) BeanPropertyComparator(org.kuali.kfs.krad.util.BeanPropertyComparator) Document(org.kuali.rice.kew.api.document.Document)

Example 3 with Document

use of org.kuali.rice.kew.api.document.Document 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;
    Document 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 : KRADConstants.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(KRADConstants.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.rice.kew.api.document.DocumentStatus) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow) Document(org.kuali.rice.kew.api.document.Document)

Example 4 with Document

use of org.kuali.rice.kew.api.document.Document 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;
    Document 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.rice.kew.api.document.DocumentStatus) TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow) Document(org.kuali.rice.kew.api.document.Document)

Example 5 with Document

use of org.kuali.rice.kew.api.document.Document in project cu-kfs by CU-CommunityApps.

the class TransactionRowPdpBuilder method updateTransactionRowsFromWorkflowDocuments.

@Override
void updateTransactionRowsFromWorkflowDocuments(ResultSet rs, T summary) throws SQLException {
    TransactionDetailRow detailRow = summary.transactionDetailRow;
    String documentId;
    String initiatorPrincipalId;
    String initiatorPrincipalName;
    String vendorTaxNumber;
    Document document;
    // Perform row updates as needed.
    while (rs.next()) {
        // Only update PDP-related rows.
        if (!DisbursementVoucherConstants.DOCUMENT_TYPE_CODE.equals(rs.getString(detailRow.documentType.index))) {
            // Initialize variables.
            documentId = rs.getString(detailRow.documentNumber.index);
            initiatorPrincipalId = null;
            vendorTaxNumber = rs.getString(detailRow.vendorTaxNumber.index);
            // Retrieve document info.
            document = getWorkflowDocumentForTaxRow(documentId, summary);
            if (document != null) {
                initiatorPrincipalId = document.getInitiatorPrincipalId();
            }
            // Check for null objects as needed, and get the initiator's principal name. (NOTE: Uses temp chart from doc title field.)
            initiatorPrincipalName = checkForEntityAndAccountAndOrgExistence(initiatorPrincipalId, rs.getString(detailRow.documentTitle.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);
            // Update the current row.
            rs.updateRow();
        }
    }
}
Also used : TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow) Document(org.kuali.rice.kew.api.document.Document)

Aggregations

Document (org.kuali.rice.kew.api.document.Document)5 TransactionDetailRow (edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow)3 DocumentStatus (org.kuali.rice.kew.api.document.DocumentStatus)3 DocumentSearchCriteria (org.kuali.rice.kew.api.document.search.DocumentSearchCriteria)2 DocumentSearchResult (org.kuali.rice.kew.api.document.search.DocumentSearchResult)2 DocumentSearchResults (org.kuali.rice.kew.api.document.search.DocumentSearchResults)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 AdvanceDepositDocument (org.kuali.kfs.fp.document.AdvanceDepositDocument)1 BeanPropertyComparator (org.kuali.kfs.krad.util.BeanPropertyComparator)1 Person (org.kuali.rice.kim.api.identity.Person)1