Search in sources :

Example 1 with DocumentRouteHeaderValue

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

the class CuAutoDisapproveDocumentsServiceImpl method getDocumentsWithActualWorkflowStatus.

/**
 * CU Customization:
 *
 * There is a known Rice issue where the KFS document headers are not auto-saved when a KFS
 * document gets recalled to the action list. This is due to Rice explicitly avoiding any
 * auto-saves on documents moving to SAVED status, to prevent Optimistic Locking problems
 * for end-users as per the Rice PostProcessorServiceImpl code comments.
 *
 * 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.rice.kew.routeheader.DocumentRouteHeaderValue) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 FinancialSystemDocumentHeader (org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader)1 DocumentRouteHeaderValue (org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue)1