Example usage for org.springframework.util CollectionUtils containsAny

List of usage examples for org.springframework.util CollectionUtils containsAny

Introduction

In this page you can find the example usage for org.springframework.util CollectionUtils containsAny.

Prototype

public static boolean containsAny(Collection<?> source, Collection<?> candidates) 

Source Link

Document

Return true if any element in ' candidates ' is contained in ' source '; otherwise returns false .

Usage

From source file:org.fsl.roms.service.action.RoadCheckServiceAction.java

/**
 * This is a helper function which looks at the created passed in road check offence outcomes and compares with the
 * associatedDocs to create ScannedDOC using the scanned document web service.
 * //from  w w  w  .j ava  2 s.c om
 * @param savedDocViews
 * @param associatedDocs
 * @throws fsl.ta.toms.roms.webservices.scanneddocupload.NoRecordFoundException
 * @throws fsl.ta.toms.roms.webservices.scanneddocupload.ErrorSavingException
 */
public void uploadScannedDocuments(List<DocumentViewBO> savedDocViews, List<AssociatedDocView> associatedDocs)
        throws ErrorSavingException, RequiredFieldMissingException {
    for (AssociatedDocView associatedDoc : associatedDocs) {
        // find out if any off the offence ids from road check offence outcome match the offence ids in the
        // associated doc
        if (associatedDoc.getUploadedFile() != null) {
            for (DocumentViewBO docView : savedDocViews) {
                if (docView.getDocumentTypeCode().equalsIgnoreCase(associatedDoc.getDocumentTypeCode())) {
                    List<Integer> offenceIds = new ArrayList<Integer>();

                    if (docView.getListOfOffences().get(0) instanceof OffenceBO) {

                        for (OffenceBO offence : docView.getListOfOffences()) {
                            offenceIds.add(offence.getOffenceId());
                        }
                    } else {

                        for (Object offence : docView.getListOfOffences()) {
                            offenceIds.add(((OffenceBO) offence).getOffenceId());
                        }
                    }

                    if (CollectionUtils.containsAny(associatedDoc.getOffenceIDs(), offenceIds)) {
                        // Found a match. Create the Scanned Document object and call the web service then break
                        // from the inner loop.
                        ScannedDocBO scannedDoc = new ScannedDocBO();

                        scannedDoc.setCurrentUsername(this.getRomsLoggedInUser().getUsername());

                        scannedDoc.setFileContents(associatedDoc.getUploadedFile().getContents());

                        scannedDoc.setMimeType(associatedDoc.getUploadedFile().getContentType());

                        scannedDoc.setDescription("Scanned Manual Document");

                        scannedDoc.setRoadCheckOffenceOutcomeId(docView.getRoadCheckOffenceOutcomeCode());

                        scannedDoc.setDocType(associatedDoc.getDocumentType());

                        scannedDoc.setManualSerialNo(associatedDoc.getSerialNum());

                        try {
                            DocumentViewBO documentView = new DocumentViewBO();
                            //copyFields(documentView,docView);
                            documentView = copyDocumentViewBO(documentView, docView);

                            documentView.setManualSerialNo(associatedDoc.getSerialNum());

                            this.getScannedDocUploadService().uploadFile(scannedDoc, documentView);
                        } catch (Exception e) {
                            // In the event that one document cannot be uploaded continue to process the rest of the
                            // documents.
                            e.printStackTrace();
                        }

                        break;
                    }
                }
            }
        }
    }
}