microsoftgraph / microsoftgraph/msgraph-sdk-java
Boiler plate when iterating through collections
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 444
- Forks
- 154
- Ø Merge
- 18 Std. 28 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
Hello, i have a small question.
https://github.com/microsoftgraph/msgraph-sdk-java/blob/dev/docs/upgrade-to-v6.md#pageiterator
- With the new page iterator there is a boilerplate associated with each request and iterating through it. Since a new page iterator would need to be created for each request.
- I was wondering if there is a generic way to create an iterator to run on collection requests and delta collection requests.
So I created this code, from looking at the generated code in the msft graph sdk:
public static <T extends Parsable> void genericIterator(
GraphServiceClient graphClient,
BaseDeltaFunctionResponse res,
Consumer<T> processEntity,
Consumer<String> processDeltaLink) {
PageIterator<T, BaseDeltaFunctionResponse> pageIterator;
try {
pageIterator = new PageIterator.Builder<T, BaseDeltaFunctionResponse>()
.client(graphClient)
.collectionPage(res)
.collectionPageFactory(BaseDeltaFunctionResponse::createFromDiscriminatorValue)
.processPageItemCallback(entity -> {
processEntity.accept(entity);
return true;
}).build();
pageIterator.iterate();
processDeltaLink.accept(pageIterator.getDeltaLink());
} catch (ApiException | ReflectiveOperationException e) {
log.error("Error ", e);
}
}
public static <T extends Parsable> void genericIterator(
GraphServiceClient graphClient,
BaseCollectionPaginationCountResponse res,
Consumer<T> processGroupOwner) {
PageIterator<T, BaseCollectionPaginationCountResponse> pageIterator;
try {
pageIterator = new PageIterator.Builder<T, BaseCollectionPaginationCountResponse>()
.client(graphClient)
.collectionPage(res)
.collectionPageFactory(BaseCollectionPaginationCountResponse::createFromDiscriminatorValue)
.processPageItemCallback(entity -> {
processGroupOwner.accept(entity);
return true;
}).build();
pageIterator.iterate();
} catch (ApiException | ReflectiveOperationException e) {
log.error("Error ", e);
}
}
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:
DeltaGetResponse res2 = graphServiceClient.groups().delta().get();
genericIterator(graphServiceClient, res2, (Group group) -> {
log.info("Group: {} {}", group.getId(), group.getDisplayName());
}, (String deltaLink) -> {
log.info("DeltaLink: {}", deltaLink);
});
java.lang.IllegalAccessException: NO_COLLECTION_PROPERTY_ERROR
at com.microsoft.graph.core.tasks.PageIterator.extractEntityListFromParsable(PageIterator.java:300)
at com.microsoft.graph.core.tasks.PageIterator.interpageIterate(PageIterator.java:250)
at com.microsoft.graph.core.tasks.PageIterator.iterate(PageIterator.java:272)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Implementierung von PageIterator in com.microsoft.graph.core.tasks.PageIterator.java, insbesondere mit extractEntityListFromParsable und dem Iterationspfad zwischen den Seiten, und überprüfe anschließend den Abschnitt zu PageIterator in docs/upgrade-to-v6.md. Stelle das generische Delta-Beispiel aus dem Issue nach und ermittle, ob Anforderungen für Collections und Delta-Collections einen kompakten Iterator gemeinsam nutzen können; als erledigt gilt die Aufgabe, wenn das unterstützte Verhalten und die erforderliche API-Änderung klar sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- api
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100