The Microsoft Graph Java SDK example 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)
// 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("List item downloaded - id={}, driveItemId={}, numBytes={}", li.getId(), driveItemId, bytes.length);
try {
InputStream isFromFetcher = microsoftGraphFetcher.fetch(siteDriveId + "," + driveItemId, new Metadata());
byte[] bytesFromFetcher = IOUtils.toByteArray(isFromFetcher);
Assertions.assertEquals(bytesFromFetcher, bytes);
} catch (TikaException e) {
Assertions.fail(e);
}
} 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?