Search in sources :

Example 1 with DocumentSearchResults

use of org.kuali.rice.kew.api.document.search.DocumentSearchResults 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 DocumentSearchResults

use of org.kuali.rice.kew.api.document.search.DocumentSearchResults 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 DocumentSearchResults

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

the class CuElectronicInvoiceHelperServiceImpl method retrieveDocumentsToRoute.

/**
 * Returns a list of all initiated but not yet routed payment request or reject documents, using the KualiWorkflowInfo service.
 * @return a list of payment request or eirt documents to route
 */
protected Collection<String> retrieveDocumentsToRoute(String statusCode, Class<?> document) throws WorkflowException, RemoteException {
    // This is very much from pcardserviceimpl
    Set<String> documentIds = new HashSet<String>();
    DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create();
    criteria.setDocumentTypeName(SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(document));
    criteria.setDocumentStatuses(Collections.singletonList(DocumentStatus.fromCode(statusCode)));
    DocumentSearchCriteria crit = criteria.build();
    int maxResults = SpringContext.getBean(FinancialSystemDocumentService.class).getMaxResultCap(crit);
    int iterations = SpringContext.getBean(FinancialSystemDocumentService.class).getFetchMoreIterationLimit();
    for (int i = 0; i < iterations; i++) {
        LOG.debug("Fetch Iteration: " + i);
        criteria.setStartAtIndex(maxResults * i);
        crit = criteria.build();
        LOG.debug("Max Results: " + criteria.getStartAtIndex());
        DocumentSearchResults results = KewApiServiceLocator.getWorkflowDocumentService().documentSearch(GlobalVariables.getUserSession().getPrincipalId(), crit);
        if (results.getSearchResults().isEmpty()) {
            break;
        }
        for (DocumentSearchResult resultRow : results.getSearchResults()) {
            documentIds.add(resultRow.getDocument().getDocumentId());
            LOG.debug(resultRow.getDocument().getDocumentId());
        }
    }
    return documentIds;
}
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) FinancialSystemDocumentService(org.kuali.kfs.sys.document.service.FinancialSystemDocumentService) HashSet(java.util.HashSet)

Aggregations

DocumentSearchCriteria (org.kuali.rice.kew.api.document.search.DocumentSearchCriteria)3 DocumentSearchResult (org.kuali.rice.kew.api.document.search.DocumentSearchResult)3 DocumentSearchResults (org.kuali.rice.kew.api.document.search.DocumentSearchResults)3 Document (org.kuali.rice.kew.api.document.Document)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 AdvanceDepositDocument (org.kuali.kfs.fp.document.AdvanceDepositDocument)1 BeanPropertyComparator (org.kuali.kfs.krad.util.BeanPropertyComparator)1 FinancialSystemDocumentService (org.kuali.kfs.sys.document.service.FinancialSystemDocumentService)1 DocumentStatus (org.kuali.rice.kew.api.document.DocumentStatus)1 Person (org.kuali.rice.kim.api.identity.Person)1