microsoftgraph / microsoftgraph/msgraph-sdk-java
Improve paging functionality
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 444
- Fork
- 154
- Merge medio
- 18h 28m
- PR unite (30g)
- 4
Descrizione
Is your feature request related to a problem? Please describe the problem.
In my opinion, the code required for getting all paged results of a collection request is not ideal. In v5 I had a generic method that handled it for all types, but I couldn't achieve the same using v6. Mainly because the classes for the original request use a RequestConfiguration object and the classes for the paginated requests use a RequestInformation object and they seem to be wholly incompatible.
This is the best I could come up with:
public List<User> getAllUsers(List<String> selectAttributes, String filter)
{
UserCollectionResponse userCollectionResponse = graphClient.users().get(
requestConfig ->
{
if (!selectAttributes.isEmpty())
{
requestConfig.queryParameters.select = selectAttributes.toArray(new String[0]);
if (selectAttributes.contains("manager"))
requestConfig.queryParameters.expand = new String[]{"manager"};
}
if (filter != null)
requestConfig.queryParameters.filter = filter;
});
UnaryOperator<RequestInformation> requestInformation =
requestInfo ->
{
if (!selectAttributes.isEmpty())
{
requestInfo.addQueryParameter("%24select", selectAttributes.toArray(new String[0]));
if (selectAttributes.contains("manager"))
requestInfo.addQueryParameter("%24expand", new String[]{"manager"});
}
if (filter != null)
requestInfo.addQueryParameter("%24filter", filter);
return requestInfo;
};
return loadPagedEntities(userCollectionResponse, UserCollectionResponse::createFromDiscriminatorValue, requestInformation);
}
private <T extends Parsable> List<T> loadPagedEntities(
BaseCollectionPaginationCountResponse baseCollectionPaginationCountResponse,
Function<ParseNode, BaseCollectionPaginationCountResponse> collectionPageFactoryFunction,
UnaryOperator<RequestInformation> requestInformation)
{
try
{
List<T> entities = new ArrayList<>();
PageIterator<T, BaseCollectionPaginationCountResponse> pageIterator =
new PageIterator.Builder<T, BaseCollectionPaginationCountResponse>()
.client(graphClient)
.collectionPage(Objects.requireNonNull(baseCollectionPaginationCountResponse))
.collectionPageFactory(collectionPageFactoryFunction::apply)
.requestConfigurator(requestInformation)
.processPageItemCallback(entities::add)
.build();
pageIterator.iterate();
return entities;
}
catch (ReflectiveOperationException e)
{
throw new RuntimeException(e);
}
}
What irks me most about this, is that I have to specify the query parameters twice and using different syntax! Especially the "%24..." is pretty ugly.
Describe the solution you'd like.
The best solution, of course, would be if the SDK handled this transparently:
List<User> allUsers = graphClient.users().getAll(requestConfig -> ...);
The next best solution would be some kind of compatibility between RequestConfiguration and RequestInformation, so the query parameters would only have to specified once.
What do you think?
Additional context?
No response
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia ispezionando le Java SDK APIs indicate nel report: RequestConfiguration, RequestInformation e PageIterator. Riproduci il flusso di paginazione di esempio e confronta come vengono configurati i parametri di query per la prima richiesta e per quelle successive. Il lavoro è completo quando i chiamanti possono configurare i parametri di query della paginazione senza duplicarli o usare nomi codificati come "%24select" e "%24filter".
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- api
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100