-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boiler plate when iterating through collections #1965
Comments
@Moh-inc thank you for your feedback and proposed improvements. These are really helpful to the future of this SDK. The exception is thrown because the HTTP response returned after hitting the nextLink URL contains a "value" property but the It would be ideal if the The same issue is likely to affect your implementation for the generic collections if a next page is returned. |
I do however like the idea of adding a convenience method to reduce the boilerplate to instantiate a |
Hello @Moh-inc , I just wanted to chime in here, since we are using something similiar in our project. We use the following method to iterate and put elements into a list. Please Excuse the random ordering of the parameters. Hopefully this can be useful for you. We are able to use this method for both normal Collection requests and Delta Collection requests. public static <TEntity extends Parsable, TCollectionPage extends Parsable & AdditionalDataHolder> String getList(
@Nonnull List<TEntity> theList,
@Nonnull GraphServiceClient gc,
TCollectionPage pageResponse,
@Nonnull ParsableFactory<TCollectionPage> collectionPageFactory
)
throws ReflectiveOperationException {
if(pageResponse== null) {
return null;
}
var pageIterator = new PageIterator.Builder<TEntity, TCollectionPage>()
.client(gc)
.collectionPage(pageResponse)
.collectionPageFactory(collectionPageFactory)
.processPageItemCallback((item) -> {
theList.add(item);
return true;
}).build();
pageIterator.iterate();
return pageIterator.getDeltaLink(); Example usage: String deltaString = "... the delta string from last time";
GraphServiceClient graphClient = ... //get your client
List<Group> groupList= new ArrayList<>();
DeltaGetResponse groups = graphClient.groups().delta().withUrl(deltaString).get();
String groupDeltaLink = GraphUtil.getList(groupList, graphClient, groups, DeltaGetResponse::createFromDiscriminatorValue); |
@etcoyvindf Looks good thank you for sharing! |
Hello, i have a small question.
https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/docs/upgrade-to-v6.md#pageiterator
So I created this code, from looking at the generated code in the msft graph sdk:
This second method works with general collectors, but not the first one for delta collections.
I was wondering if this is even recommending considering that the sdk is based on code generations and/or if there is a way to iterate over collections in a more concise manner than the current page iterator.
Error received from the generic delta collection iterator:
The text was updated successfully, but these errors were encountered: