In Microsoft graph sdk 6.4.0 using new PageIterator - How do you use collectionPageFactory?

14 Views Asked by At

There is a new PageIterator in 6.4.0 version of Microsoft Graph Java SDK.

https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/docs/upgrade-to-v6.md#pageiterator

This Example of the Microsoft Graph Java SDK for iterating through items looks like this:

PageIterator<ListItem, ListItemCollectionResponse> pageIterator = new PageIterator.Builder<ListItem, ListItemCollectionResponse>()
            .client(graphClient)
            // The first page of the collection is passed to the collectionPage method
            .collectionPage(response)
            // CollectionPageFactory is called to create a new collection page from the nextLink
            .collectionPageFactory(ListItemCollectionResponse::createFromDiscriminatorValue) // i just copy pasted this from the example. What does it do? 
            // ProcessPageItemCallback is called for each item in the collection
            .processPageItemCallback(li -> {
                String driveItemId = li.getDriveItem().getId();
                InputStream is = graphClient.drives().byDriveId(siteDriveId)
                        .items()
                        .byDriveItemId(driveItemId)
                        .content()
                        .get();
                try {
                    byte[] bytes = IOUtils.toByteArray(is);
                    LOGGER.info("Read {} bytes", bytes.length);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                return true;
            }).build();
    pageIterator.iterate();

Can someone please describe what the collectionPageFactory method's purpose is? ListItemCollectionResponse::createFromDiscriminatorValue - what is a discriminator?

0

There are 0 best solutions below